For converting Drupal internal links to HTML href tags, the l() function is very useful not only in modules, but also could be needed when creating content for nodes. But this function is only available when PHP is enabled for content, it cannot be used when HTML or Filtered HTML input format is used.

Given that the filter module is now part of the core, am wondering if it would be useful to have a way in Drupal core to allow easier entry of Drupal internal links - taking care of things like adding base_path() prefixes, converting to an alias if available, etc.

Here's a module (submitted to public domain, anyone can do what they wish with this) that allows this (see linkfilter-0.1.zip - tested with both 4.7.6 and 5.1, see the top of linkfilter.module for install instructions), here's the long help:

Link filter tags [l:URL text] in the input text will be replaced with a link to the given URL, which can be a Drupal link or a external web link. Handling Drupal install in a sub-directory or alias conversion happens automatically.

Examples:
[l:node/281 Blue Sun] will link to the internal Drupal page, using alias if available, with the label "Blue Sun"
[l:travel/blue-sun Blue Sun] will link to the internal Drupal page, with the label "Blue Sun"
[l:travel/blue-sun] will link to the internal Drupal page, with the text copied from the URL "travel/blue-sun"
[l:http://www.google.com/ Search!] will link to the external web link, with the text "Search!"

Characters space " " and right square bracket "]" cannot be used.
In URL, for space use %20, for right square bracket ] use %5D URL Escape Code.
In text words, space can be used. For right square bracket ] use ] Entity Code.

There is also the freelinking module that offers some wiki-like capabilities, but it too does not offer any shortcuts for internal Drupal links. And it is far more powerful, and hence may have more of a performance impact.

Comments

bwooster47’s picture

Here's the place with details and download info for yet-another-url-link-filter, and the reasons why this was built:
  Link Filter Drupal Module

The goal for this Link filter is to be somewhat like the URL filter included with Drupal, with the additional requirement to be Drupal installation directory independent so that the URL tags don't have to be re-edited when a Drupal site is moved to a different sub-directory. Additionally, it allows for link text to be specified for the URL.

It does not use the Drupal l() or url() functions, but does make use of the $base_root and $base_url global variables.

tinthing’s picture

Just a Thank You for this module - I'd been scratching my head trying to understand why a system as extensive and powerful as Drupal didn't have a simple way of cross-linking between pages without descending into html, and then mercifully this module came along. I put it straight into service on my sites (Drupal v5.1) and its great.

Pasqualle’s picture