Anyone up for explaining the $options array in the l() function for D6?

vinayakaya's picture
public
vinayakaya - Mon, 2008-05-19 02:18

I am trying to get my head around the new l() function in drupal 6, l($text, $path, $options = array()), but I didn't understand the arguments after the $path argument in version 5 and I haven't been able to find a reference on api.drupal.org (or anywhere on the web for that matter)that explains the available indexes and values for the $options array.

Is there anyone out there that would be willing to write a short explanation describing how to use this array and listing the available values? Or if it has already been written perhaps you could enlighten me with a link.

Thanks


$option in l()

g.idema - Mon, 2008-05-19 08:41

It's in the api documentation at: http://api.drupal.org/api/function/l/6 and http://api.drupal.org/api/function/l/5
The options from the Drupal 5 version were put together in Drupal 6 and an extra option 'alias' was added.

A little explanation about the terms:
Query: the part after the ? in the url (x=1&y=two etc.)
Fragment: the part after the # refering to a named id inside the document

The rest looks clearly documented to me, but please let me know if you have any other questions.

Thank you that clears that up

vinayakaya's picture
vinayakaya - Mon, 2008-05-19 15:51

Thank you for that clarification. Your explanation made the rest make sense.


One other question relating to the attributes array

vinayakaya's picture
vinayakaya - Mon, 2008-05-19 21:42

One thing I didn't see in the documentation is the available values for the attributes array that sits inside the options array. I know that this adds classes to the anchor tag for that link, but how does this work out to be an array?

Web design, Drupal theming, and logo design:
http://www.translationdesigns.com


Very thin abstraction layer

Intchanter's picture
Intchanter - Mon, 2008-05-19 22:12

The attributes array is for any attributes that the a tag will have besides href, including classes.

http://www.w3schools.com/TAGS/tag_a.asp has a list of current attributes.


example

jrglasgow@drupal.org's picture
jrglasgow@drupal.org - Mon, 2008-05-19 22:35

for example to link to the above reply, the link you would need is this
<a href="/node/11554#comment-37717" class="active">Very thin abstraction layer</a>
this would be built with the l() function like this:

<?php
l
('Very thin abstraction layer', 'node/11554', array('fragment' => 'comment-37717', 'class' => 'active');
// really you don't need the class set to active, because l() adds class="active" by default.
?>

If you wanted to target another frame or window, or even a blank window you would do it like this:

<?php
l
('Very thin abstraction layer', 'node/11554', array('fragment' => 'comment-37717', 'target' => _blank);
?>

this forces the URL to open in a new window, or tab depending on the browser settings, and would result in a link looking like this
<a href="/node/11554#comment-37717" class="active" target="_blank">Very thin abstraction layer</a>


Re: example

g.idema - Tue, 2008-05-20 07:47

This examples above are not correct. The miss the 'atttributes' array that surrounds the attributes, which is just what vinayakaya's question was about.

It should be:

<?php
l
('Very thin abstraction layer', 'node/11554', array('fragment' => 'comment-37717', 'attributes' => array('class' => 'active', 'target' => '_blank'));>
// really you don't need the class set to active, because l() adds class="active" by default.
?>

error

jrglasgow@drupal.org's picture
jrglasgow@drupal.org - Tue, 2008-05-20 16:47

my bad, I missed that one. I guess I need to pay more attention next time.


Thank you

vinayakaya's picture
vinayakaya - Tue, 2008-05-20 17:24

Thank you for the example.

Web design, Drupal theming, and logo design:
http://www.translationdesigns.com