Language
  • English
  • Français
Drupal custom theming or module development price estimate calculator

Question about l() function

Hi,Aaron
Would you like to tell me more about :"http://www.pixelclever.com/how-and-why-use-l-function-create-links-drupal-programming"?

as that:

which file should I put the following code into? :

l($text, $path, $options = array())
or the example: print l('This is the link text', 'node/2');

$options = array(
'attributes' => array(),
'html' => TRUE,
);
l('', 'node/1', $options);

should I type the code in the page.tpl.php or the others?

The l() function can be used

Aaron's picture

The l() function can be used anywhere that php can be used within Drupal. That means from within any module, within template.php, or any include file that gets called by a module or theme. It basically is just a replacement for doing something like this:

$output = '<a href="/some-example-link" class="example-class">'.$some_dynamic_content_here.'</a>';
print $output;

Using l() insures that the link starts from the correct context (starting from the base path) and it adds active classes and other information that you wouldn't want to have to calculate on your own.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Ask a question related to Drupal development or administration