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/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.
  • 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 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 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.

▾ 110 functions call l()

actions_synchronize in includes/actions.inc
Synchronize actions that are provided by modules.
aggregator_form_category_submit in modules/aggregator/aggregator.admin.inc
Process aggregator_form_category form submissions.
aggregator_form_feed_submit in modules/aggregator/aggregator.admin.inc
Process aggregator_form_feed form submissions.
aggregator_view in modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
block_admin_display_form in modules/block/block.admin.inc
Generate main blocks administration form.
blogapi_blogger_edit_post in modules/blogapi/blogapi.module
Blogging API callback. Modifies the specified blog node.
blogapi_blogger_new_post in modules/blogapi/blogapi.module
Blogging API callback. Inserts a new blog post as a node.
blog_form in modules/blog/blog.module
Implementation of hook_form().
blog_page_last in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of all users.
blog_page_user in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of a given user.
blog_user in modules/blog/blog.module
Implementation of hook_user().
blog_view in modules/blog/blog.module
Implementation of hook_view().
book_admin_edit_submit in modules/book/book.admin.inc
Handle submission of the book administrative page form.
book_admin_overview in modules/book/book.admin.inc
Returns an administrative overview of all books.
book_render in modules/book/book.pages.inc
Menu callback; prints a listing of all books.
chameleon_comment in themes/chameleon/chameleon.theme
chameleon_node in themes/chameleon/chameleon.theme
chameleon_page in themes/chameleon/chameleon.theme
comment_admin_overview in modules/comment/comment.admin.inc
Form builder; Builds the comment overview form for the admin.
comment_admin_overview_submit in modules/comment/comment.admin.inc
Process comment_admin_overview form submissions.
comment_reply in modules/comment/comment.pages.inc
This function is responsible for generating a comment reply form. There are several cases that have to be handled, including:
comment_save in modules/comment/comment.module
Accepts a submission of new or changed comment content.
confirm_form in modules/system/system.module
Output a confirmation form
contact_admin_categories in modules/contact/contact.admin.inc
Categories/list tab.
contact_admin_edit_submit in modules/contact/contact.admin.inc
Process the contact category edit page form submission.
dblog_event in modules/dblog/dblog.admin.inc
Menu callback; displays details about a log message.
dblog_overview in modules/dblog/dblog.admin.inc
Menu callback; displays a listing of log messages.
filter_admin_format_form in modules/filter/filter.admin.inc
Generate a filter format form.
filter_admin_overview in modules/filter/filter.admin.inc
Menu callback; Displays a list of all input formats and which one is the default.
forum_nodeapi in modules/forum/forum.module
Implementation of hook_nodeapi().
forum_overview in modules/forum/forum.admin.inc
Returns an overview list of existing forums and containers
help_links_as_list in modules/help/help.admin.inc
hook_requirements in developer/hooks/install.php
Check installation requirements and do status reporting.
locale_update_6005 in modules/locale/locale.install
Change language setting variable of content types.
menu_edit_item in modules/menu/menu.admin.inc
Menu callback; Build the menu link editing form.
menu_get_active_breadcrumb in includes/menu.inc
Get the breadcrumb for the current page, as determined by the active trail.
node_admin_nodes in modules/node/node.admin.inc
Form builder: Builds the node administration overview.
node_feed in modules/node/node.module
A generic function for generating RSS feeds from a set of nodes.
node_form_submit in modules/node/node.pages.inc
node_overview_types in modules/node/content_types.inc
Displays the content type admin overview page.
node_revision_overview in modules/node/node.pages.inc
Generate an overview table of older revisions of a node.
node_title_list in modules/node/node.module
Gather a listing of links to nodes.
node_type_form_submit in modules/node/content_types.inc
Implementation of hook_form_submit().
openid_form_alter in modules/openid/openid.module
Implementation of hook_form_alter : adds OpenID login to the login forms.
openid_user_identities in modules/openid/openid.pages.inc
Menu callback; Manage OpenID identities for the specified user.
path_admin_overview in modules/path/path.admin.inc
Return a listing of all defined URL aliases. When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.
php_install in modules/php/php.install
Implementation of hook_install().
poll_page in modules/poll/poll.pages.inc
Menu callback to provide a simple list of all polls available.
profile_admin_overview in modules/profile/profile.admin.inc
Form builder to display a listing of all editable profile fields.
profile_block in modules/profile/profile.module
Implementation of hook_block().
profile_field_delete_submit in modules/profile/profile.admin.inc
Process a field delete form submission.
profile_field_form_submit in modules/profile/profile.admin.inc
Process profile_field_form submissions.
profile_view_field in modules/profile/profile.module
search_view in modules/search/search.pages.inc
Menu callback; presents the search form and/or search results.
statistics_access_log in modules/statistics/statistics.admin.inc
Menu callback; Displays recent page accesses.
statistics_node_tracker in modules/statistics/statistics.pages.inc
statistics_recent_hits in modules/statistics/statistics.admin.inc
Menu callback; presents the "recent hits" page.
statistics_top_visitors in modules/statistics/statistics.admin.inc
Menu callback; presents the "top visitors" page.
statistics_user_tracker in modules/statistics/statistics.pages.inc
system_actions_manage in modules/system/system.module
Menu callback. Display an overview of available and configured actions.
system_admin_by_module in modules/system/system.admin.inc
Menu callback; prints a listing of admin tasks for each installed module.
system_get_module_admin_tasks in modules/system/system.module
Generate a list of tasks offered by a specified module.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
system_themes_form in modules/system/system.admin.inc
Menu callback; displays a listing of all themes.
tablesort_header in includes/tablesort.inc
Format a column header.
taxonomy_form_term_submit in modules/taxonomy/taxonomy.admin.inc
Submit handler to insert or update a term.
taxonomy_form_vocabulary_submit in modules/taxonomy/taxonomy.admin.inc
Accept the form submission for a vocabulary and save the results.
taxonomy_overview_terms in modules/taxonomy/taxonomy.admin.inc
Form builder for the taxonomy terms overview.
taxonomy_overview_vocabularies in modules/taxonomy/taxonomy.admin.inc
Form builder to list and manage vocabularies.
taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Menu callback; displays all nodes associated with a term.
template_preprocess_aggregator_feed_source in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-feed-source.tpl.php.
template_preprocess_aggregator_item in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-item.tpl.php.
template_preprocess_comment in modules/comment/comment.module
Process variables for comment.tpl.php.
template_preprocess_comment_folded in modules/comment/comment.module
Process variables for comment-folded.tpl.php.
template_preprocess_forums in modules/forum/forum.module
Process variables for forums.tpl.php
template_preprocess_forum_topic_list in modules/forum/forum.module
Preprocess variables to format the topic listing.
template_preprocess_user_picture in modules/user/user.module
Process variables for user-picture.tpl.php.
theme_admin_block_content in modules/system/system.admin.inc
This function formats the content of an administrative block.
theme_admin_page in modules/system/system.admin.inc
This function formats an administrative page for viewing.
theme_aggregator_block_item in modules/aggregator/aggregator.module
Format an individual feed item for display in the block.
theme_book_admin_table in modules/book/book.admin.inc
Theme function for the book administration page form.
theme_book_title_link in modules/book/book.module
Generate the HTML output for a link to a book title when used as a block title.
theme_comment_block in modules/comment/comment.module
Returns a formatted list of recent comments to be displayed in the comment block.
theme_filter_tips_more_info in modules/filter/filter.module
Format a link to the more extensive filter tips.
theme_links in includes/theme.inc
Return a themed set of links.
theme_locale_languages_overview_form in includes/locale.inc
Theme the language overview form.
theme_menu_item_link in includes/menu.inc
Generate the HTML output for a single menu link.
theme_node_add_list in modules/node/node.pages.inc
Display the list of available node types for node creation.
theme_pager_link in includes/pager.inc
Format a link to a specific query result page.
theme_system_powered_by in modules/system/system.module
Format the Powered by Drupal text.
theme_update_report in modules/update/update.report.inc
Theme project status report.
theme_update_version in modules/update/update.report.inc
Theme the version display of a project.
theme_upload_attachments in modules/upload/upload.module
Displays file attachments in table
theme_username in includes/theme.inc
Format a username.
theme_user_admin_new_role in modules/user/user.admin.inc
Theme the new-role form.
tracker_page in modules/tracker/tracker.pages.inc
Menu callback. Prints a listing of active nodes on the site.
translation_node_overview in modules/translation/translation.pages.inc
Overview page for a node's translations.
trigger_assign_form in modules/trigger/trigger.admin.inc
Create the form definition for assigning an action to a hook-op combination.
user_admin_access in modules/user/user.admin.inc
Menu callback: list all access rules
user_admin_account in modules/user/user.admin.inc
Form builder; User administration page.
user_external_login_register in modules/user/user.module
Helper function for authentication modules. Either login in or registers the current user, based on username. Either way, the global $user object is populated based on $name.
user_login_block in modules/user/user.module
user_register_submit in modules/user/user.module
Submit handler for the user registration form.
_locale_translate_seek in includes/locale.inc
Perform a string search and display results in a table
_menu_overview_tree_form in modules/menu/menu.admin.inc
Recursive helper function for menu_overview_form().
_menu_site_is_offline in includes/menu.inc
Checks whether the site is off-line for maintenance.
_node_mass_update_batch_process in modules/node/node.admin.inc
Node Mass Update Batch operation
_statistics_link in modules/statistics/statistics.module
It is possible to adjust the width of columns generated by the statistics module.
_update_refresh in modules/update/update.fetch.inc
Fetch project info via XML from a central server.
_update_requirement_check in modules/update/update.module
Private helper method to fill in the requirements array.

Code

includes/common.inc, line 1574

<?php
function l($text, $path, $options = array()) {
  global $language;

  // 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->language)) {
    if (isset($options['attributes']['class'])) {
      $options['attributes']['class'] .= ' active';
    }
    else {
      $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']);
  }

  return '<a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'>'. ($options['html'] ? $text : check_plain($text)) .'</a>';
}
?>

the $options array sample

toshimitsu - Thu, 2009-08-27 03:02

The following link was useful for me so I thought I should post it here:

Anyone up for explaining the $options array in the l() function for D6?
http://groups.drupal.org/node/11554

thanks.

It is not necessary to wrap

rszrama - Mon, 2009-09-14 15:21

It is not necessary to wrap the $text argument with t() as long as the html option is FALSE (the default). l() will automatically check_plain() the link text for you.

check_plain() and t() are different

zzolo - Thu, 2009-09-17 15:40

t() is necessary if you are providing translatable text. The purpose of t() is to provide translation, while check_plain() is used to escape any possible malicious character. Often t() is used an easy way to provide secure text since it pushes things through check_plain, but this is just an added bonus. use t() for translating!.

Example with custom class, attributes

chris.cohen - Thu, 2009-09-17 09:24

This will produce a link with the class="widelink" and rel="lightbox" attributes on the a tag.

<?php
l
(
 
t('My link'),
 
'node/56',
  array(
   
'attributes' => array(
     
'class' => 'widelink',
     
'rel' => 'lightbox',
    )
  )
);
?>

Open link a in new window

chrsim79 - Sat, 2009-12-05 12:55

All components are already mentioned but no example straight into you face, so to open link in new windows use:

l(t('Title'),$url, array('attributes' => array('target' => '_blank')));

Hope this will save time for some of you.

Valid HTML

rimian - Sat, 2009-12-12 06:18

That's helpful but the HTML won't validate for strict doc types.

Something like:
l(t('Title'), $url, array('attributes' => array('onclick' => 'window.open(this.href); return false;')));
should work

Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.