Create best practices about use of the l() function and the url() function in templates

Created on 14 October 2012, about 12 years ago
Updated 12 January 2024, 11 months ago

We're coming across a lot of templates that call the l() function, and in some cases I think it can be replaced with an actual anchor tag.

The more-help-link example:
http://api.drupal.org/api/drupal/core!includes!theme.inc/function/theme_...

<div class="more-help-link">' . <a href="{{ url(path) }}" target="_blank">{{ More help|t }}</a></div>

The filter-tips-more-info example:
http://api.drupal.org/api/drupal/core!includes!theme.inc/function/theme_...

<p>{{ <a href="{{ url('filter/tips') }}" target="_blank">{{ 'More information about text formats'|t }}</p>

Does anyone have any strong feelings about this? Will it adversely affect performance?

And more importantly, should we create some best practices about when to use an anchor tag with url() and when to use l()? I was thinking:

  1. If it will not adversely affect performance
  2. If it greatly improves readability of the file

Assigning to effulgentsia since I think he knows the most about what has been discussed before about the use of l() and url() in templates, and how that may affect performance :)

Related Issues

This issue is complicated because opinions on the "best" way(s) to expose the functionality currently provided exclusively by l() are still being voiced. It's therefore hard to know what the "best" way to implement l()-like behaviour in twig templates should be as the intended role of the l() function itself within Drupal may change.

📌 Task
Status

Closed: won't fix

Component

Drupal Core Standards

Created by

🇺🇸United States jenlampton

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone

    @jenlampton, thanks for suggesting an improvement to our coding standards. And to everyone here who worked to resolve this.

    I didn't know there could be issues without a project.

    I gather from the issue summary that this is about Drupal 7 and has not been worked on for 11 years. Since Drupal 7 will be EOL in less than a year, we can be confident that there will not be any coding standard changes specific to that version of Drupal. Therefore I am closing this as a won't fix.

Production build 0.71.5 2024