function l

You are here

7 common.inc l($text, $path, array $options = array())
4.6 common.inc l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE)
4.7 common.inc l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE)
5 common.inc l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE)
6 common.inc l($text, $path, $options = array())
8 common.inc 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/node". 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/node"), it is considered an

internal link. In this case, it must be a system URL as the url() function will generate the alias.

$attributes: An associative array of HTML attributes to apply to the anchor tag.

$query: A query string to append to the link.

$fragment: A fragment identifier (named anchor) to append to the link.

$absolute: 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: Whether the title 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 encoded HTML.

Return value

an HTML string containing a link to the given path.

Related topics

106 calls to l()
aggregator_block in modules/aggregator/aggregator.module
Implementation of hook_block().
aggregator_form_category_submit in modules/aggregator/aggregator.module
Process aggregator_form_category form submissions. @todo Add delete confirmation dialog.
aggregator_form_feed_submit in modules/aggregator/aggregator.module
Process aggregator_form_feed form submissions. @todo Add delete confirmation dialog.
aggregator_view in modules/aggregator/aggregator.module
block_admin_display in modules/block/block.module
Generate main block administration form.

... See full list

File

includes/common.inc, line 1418
Common functions that many Drupal modules will need to reference.

Code

function l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE) {
  if (($path == $_GET['q']) || ($path == '<front>' && drupal_is_front_page())) {
    if (isset($attributes['class'])) {
      $attributes['class'] .= ' active';
    }
    else {
      $attributes['class'] = 'active';
    }
  }
  return '<a href="' . check_url(url($path, $query, $fragment, $absolute)) . '"' . drupal_attributes($attributes) . '>' . ($html ? $text : check_plain($text)) . '</a>';
}