0

Why does Drupal provide l() and url(), which seems to have the same purpose?

2 Answers 2

10

l() creates a clickable link (an HTML anchor tag), while url() creates just a url. If you scroll down in the l() page you'll see the following source code:

  if ($use_theme) {
    return theme('link', array('text' => $text, 'path' => $path, 'options' => $options));
  }
  // The result of url() is a plain-text URL. Because we are using it here
  // in an HTML argument context, we need to encode it properly.
  return '<a href="' . check_plain(url($path, $options)) . '"' . drupal_attributes($options['attributes']) . '>' . ($options['html'] ? $text : check_plain($text)) . '</a>';

theme_link() has a similar construction. So l() is using url() to construct the anchor.

So summarizing, the one is for clickable links, the other for plain (unclickable) url's.

1

If I've understood the documentation correctly, function url($path = NULL, array $options = array()) returns a string, which is URL of given path.

Whereas function l($text, $path, array $options = array()) has an advanced parameter $text and returns an html anchor with given text, given path and options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.