Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: How to Add Anchor to Menu

Submitted by on February 1, 2011 – 9:22 amNo Comment

You need to include anchor link to Drupal menu (<a name="anchor"></a>).
If you enter “node/15#anchor” to the “Path” field, Drupal will convert “#” to “%2523″ and you will get this on the output: “/node/15%2523anchor“. In this article I would tell you how to fix this problem.

Note:
Drupal shows ‘strict xhtml 1.1’ and anchors like this one  <a name="anchor"></a> don’t work.

We will replace this tag with ‘id’ tag in xhtml 1.1. This tag could be used for any tag.
For example, <p id="anchor"></p> and you can refer to an anchor as usual: example.com#anchor

Options

  • Show full URL
  • Redefine output function to show links in menu

Show full URL

Anchors will work in menu links if you specify full URL (http://www.example.com/example#anchor instead of /example#anchor). But full path will make your site less extensible. So you can’t always use this solution.

Redefine output function to show links in menu

You need to redefine the function – add the following code to template.php of your theme:

function phptemplate_menu_item_link($item, $link_item) {
// Convert anchors in path to proper fragment
$path = explode(‘#’, $link_item[‘path’], 2);
$fragment = !empty($path[1]) ? $path[1] : NULL;
$path = $path[0];
return l(
$item[‘title’],
$path,
!empty($item[‘description’]) ? array(‘title’ => $item[‘description’]) : array(),
!empty($item[‘query’]) ? $item[‘query’] : NULL,
$fragment,
FALSE,
FALSE
);
}

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.