Anyone up for explaining the $options array in the l() function for D6?
public
group: Drupal Dojo
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
Dojo Tags: theming functions



$option in l()
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
Thank you for that clarification. Your explanation made the rest make sense.
One other question relating to the attributes array
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
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
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:
<?phpl('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:
<?phpl('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
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:
<?phpl('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
my bad, I missed that one. I guess I need to pay more attention next time.
Thank you
Thank you for the example.
Web design, Drupal theming, and logo design:
http://www.translationdesigns.com