Alex Rivera | Logout

Drupal: Creating anchor only link with l()

Asked 2009-11-09T00:13:41.000
19

I'd like to output this

<a href='#namedanchor'>link</a>

using the l() function, so that the link just jumps to an anchor on the current page.

I expected this to work

l('link', '',  array('fragment' => 'namedanchor'));

but it creates an absolute link to www.example.com/#namedanchor instead of www.example.com/currentpage#namedanchor

Edit
Report

1 Answer

2

Here is the documentation for l

It dosn't look like it will by default use the current page when no path is defined. So you should call it like this:

l('link', 'currentpage',  array('fragment' => 'namedanchor'));
answered 2009-11-09T06:23:23.667

Your Answer