How to theme primary links like on this page?

Noddy - January 16, 2009 - 06:16

Hello drupal-community,

I would like to find a way to theme my primary links like on this page: http://www.artificestudios.com/
The HTML-code they use is:

<span><strong>Work</strong>see the magic </span>

When I use this HTML as a primary link name, the link is shown on my Drupal-page with all the tags. So it's not possible to theme it with CSS.

Anyone has an idea to get it working? Thanks alot in advance!
Noddy

Found this code in the

Keyz - January 16, 2009 - 08:14

Found this code in the Moleskin theme's template.php, which I think may do what you need. If not then you may have luck with this search: http://drupal.org/search/node/primary+links+span
Or download a variety of good-looking themes, as I believe I've seen similar code to this in many themes that need the span element in the tabs to produce more interesting/effective menus. I used something like this in the past in a D5 theme I made, though that code won't do the trick in D6.

/**
* Adding a span tag in tabs for theming purposes
*/
function phptemplate_menu_item_link($link) {
  if (empty($link['options'])) {
    $link['options'] = array();
  }

  // If an item is a LOCAL TASK, render it as a tab
  if ($link['type'] & MENU_IS_LOCAL_TASK) {
    $link['title'] = '<span class="tab">' . check_plain($link['title']) . '</span>';
    $link['options']['html'] = TRUE;
  }

  if (empty($link['type'])) {
    $true = TRUE;
  }

  return l($link['title'], $link['href'], $link['options']);
}

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

My solution

Noddy - January 18, 2009 - 18:31

Hi David,
thanks for your answer. Unfortunately the code from Moleskin template didn't help me with my problem.
But I found now a solution by myself. So for anyone who also need working HTML-tags in primary-links:

in page.tpl.php, find:

<?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>

change it to:

<?php
        $primary
= theme('links', $primary_links, array('class' => 'links primary-links'));
       
$primary_decode = html_entity_decode($primary);
        print
$primary_decode;
?>

Please note that I'm not very much into Drupal and coding, so this little hack might have drawbacks. It works perfect on my site though.

Does that code let you

Keyz - January 18, 2009 - 19:41

Does that code let you "enter" HTML directly into the menu item name? If so I'd suggest you look carefully at potential security concerns. If someone doesn't offer any confirmation or tips in this topic then maybe post a new question or ask someone in IRC to check the code. I've seen an alternate code snippet to pre-insert HTML tags around primary links... I'll see if I can find it for you.

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

Does that code let you

Noddy - January 19, 2009 - 17:54

Does that code let you "enter" HTML directly into the menu item name?

Yes, it does. I understand that it might have security issues, so I think I should better use a function that decode only the tags <span></span> and <strong></strong> instead of decoding the whole $primary_links output. I only need those two tags for theming the menu item names.

I've seen an alternate code snippet to pre-insert HTML tags around primary links. I'll see if I can find it for you.

That would be really great! I searched the forum for quite some time but couldn't find such a snippet...

Solution...

Noddy - May 1, 2009 - 14:39

For anyone with the same problem, this module allows to add HTML-tags to menu titles:
http://drupal.org/project/menu_html

 
 

Drupal is a registered trademark of Dries Buytaert.