Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 671 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drupal: Creating anchor only link with l()

#1
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`
Reply

#2
Here is the documentation for [l][1]


[1]:

[To see links please register here]


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'));

Reply

#3
If you want to create a link with just the fragment, you need to "trick" the url function a bit. As it will append the basepath to all internal urls, <code>''</code> will become <code>http://example.com</code>.

What you need to do is to set the external option to true:

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

This will give the desired

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

Alternative you could give the full url like Jeremy suggests.
Reply

#4
To create an anchor using l():

$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
l(t('link text'), $path, array('attributes' => array('name' => 'name-of-anchor')));

This will output:

<a href="/path/to/currentpage" name="name-of-anchor">link text</a>


Then, to link to this using l():

$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
l(t('link to anchor'), $path, array('fragment' => 'name-of-anchor'));

This will output:

<a href="/path/to/currentpage#name-of-anchor">link to anchor</a>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through