l
- Versions
- 4.6 – 5
l($text, $path,$attributes= array(),$query= NULL,$fragment= NULL,$absolute= FALSE,$html= FALSE)- 6
l($text, $path, $options = array())- 7
l($text, $path, array $options = array())
Format an internal Drupal link.
This function correctly handles aliased paths, and allows themes to highlight links to the current page correctly, so all internal links output by modules should be generated by this function if possible.
Parameters
$text The text to be enclosed with the anchor tag.
$path The Drupal path being linked to, such as "admin/content". Can be an external or internal URL.
- If you provide the full URL, it will be considered an external URL.
- If you provide only the path (e.g. "admin/content"), it is considered an internal link. In this case, it must be a system URL as the url() function will generate the alias.
- If you provide '<front>', it generates a link to the site's base URL (again via the url() function).
- If you provide a path, and 'alias' is set to TRUE (see below), it is used as is.
$options An associative array of additional options, with the following keys:
- 'attributes' An associative array of HTML attributes to apply to the anchor tag.
- 'query' A query string to append to the link, or an array of query key/value properties.
- 'fragment' A fragment identifier (named anchor) to append to the link. Do not include the '#' character.
- 'absolute' (default FALSE) Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
- 'html' (default FALSE) Whether $text is HTML, or just plain-text. For example for making an image a link, this must be set to TRUE, or else you will see the escaped HTML.
- 'alias' (default FALSE) Whether the given path is an alias already.
Return value
an HTML string containing a link to the given path.
Code
includes/common.inc, line 2690
<?php
function l($text, $path, array $options = array()) {
global $language_url;
static $use_theme = NULL;
// Merge in defaults.
$options += array(
'attributes' => array(),
'html' => FALSE,
);
// Append active class.
if (($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) &&
(empty($options['language']) || $options['language']->language == $language_url->language)) {
$options['attributes']['class'][] = 'active';
}
// Remove all HTML and PHP tags from a tooltip. For best performance, we act only
// if a quick strpos() pre-check gave a suspicion (because strip_tags() is expensive).
if (isset($options['attributes']['title']) && strpos($options['attributes']['title'], '<') !== FALSE) {
$options['attributes']['title'] = strip_tags($options['attributes']['title']);
}
// Determine if rendering of the link is to be done with a theme function
// or the inline default. Inline is faster, but if the theme system has been
// loaded and a module or theme implements a preprocess or process function
// or overrides the theme_link() function, then invoke theme(). Preliminary
// benchmarks indicate that invoking theme() can slow down the l() function
// by 20% or more, and that some of the link-heavy Drupal pages spend more
// than 10% of the total page request time in the l() function.
if (!isset($use_theme) && function_exists('theme')) {
// Allow edge cases to prevent theme initialization and force inline link
// rendering.
if (variable_get('theme_link', TRUE)) {
drupal_theme_initialize();
$registry = theme_get_registry();
// We don't want to duplicate functionality that's in theme(), so any
// hint of a module or theme doing anything at all special with the 'link'
// theme hook should simply result in theme() being called. This includes
// the overriding of theme_link() with an alternate function or template,
// the presence of preprocess or process functions, or the presence of
// include files.
$use_theme = !isset($registry['link']['function']) || ($registry['link']['function'] != 'theme_link');
$use_theme = $use_theme || !empty($registry['link']['preprocess functions']) || !empty($registry['link']['process functions']) || !empty($registry['link']['includes']);
}
else {
$use_theme = FALSE;
}
}
if ($use_theme) {
return theme('link', array('text' => $text, 'path' => $path, 'options' => $options));
}
return '<a href="' . check_plain(url($path, $options)) . '"' . drupal_attributes($options['attributes']) . '>' . ($options['html'] ? $text : check_plain($text)) . '</a>';
}
?>Login or register to post comments 
$options['language'] isn't
$options['language'] isn't mentioned in the parameters, use as following:
<?php$title = t('Some title');
$path = 'some/path';
$options = array(
'query' => array(
'somekey' => 'somevalue'
),
'language' => $language->language
);
$link = l($title, $path, $options);
?>
where $language->language is a valid langcode
Actually the 'language'
Actually the 'language' option should be the full language object ('language' => $language);