Hi, I'm trying to implement this technique http://www.usingdrupal.com/node/20 into the drupal 6 menu system.

The problem is that, at least to me, the all new drupal menu system is far too different from the 5th version. I tryed looking on the drupal API but still can't find a way out. Anyone there know what's the right function to customize on template.tpl.php?
Finally, I just want to add another span selector, it shouldn't be all that rocket science...

I'm building a blank new theme, but my starting points are:

-the Garland theme;
-the blueprint css framework.

Thanks in advance!

Comments

funkville’s picture

johan van grieken (mediumcool.be)

i want to achieve the same thing but no one seems to be able to help....

WorldFallz’s picture

Two things spring to mind right off the bat:

  1. the technique listed above is described for the zen theme... there's no guarantee it will work with any other theme without changes. I would try it with zen first, then go from there.
  2. in d6 the theme registry needs to be cleared when working with overrides. have you seen http://drupal.org/node/173880#theme-registry ?

===
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

Julieslv’s picture

From my last encounter with drupal, I find that using the most basic theme is a better way to start. Even though zen is recommended as a base, I found it easier to start with something ultra simple like foundation. Even then I got rid of a whole bunch of stuff in the css.

WorldFallz’s picture

that may be true, but the technique in the article referenced by the user was for zen-- it's not necessarily (and likely isn't) interchangeable with another theme. the best way to troubleshoot is to getting working as described, then adapt it to another theme.

===
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

yumminy’s picture

I struggled with this for a while too, and finally found the answer here: http://drupal.org/node/221382

Basically, make sure you have this code in your page.tpl.php file:

<?php if (!empty($primary_links)): ?>
            <?php print theme('links', $primary_links); ?>
<?php endif; ?>

And add this code in your template.php file. (I'm using PHPTemplate, modify the 'phptemplate_links' function name as needed)

<?php
/* add <span> tag around menu links */
function phptemplate_links($links, $attributes = array('class' => 'links')) {
  $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = $key;

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
        $class .= ' active';
      }
      $output .= '<li class="'. $class .'">';

      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $link['html'] = TRUE;
        $output .= l('<span>'. check_plain($link['title']) .'</span>', $link['href'], $link);
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}
?>

Don't forget to empty your cache. I found that temporarily adding this function at the top of the template.php file resolves having to constantly clear the cache. (from drupal dojo)

<?php
 /* Rebuild theme registry. Delete once development is done */
drupal_rebuild_theme_registry();
?>

The main problem with the Drupal 5 code is that the tags get printed as part of the link text, and not html. That's resolved by specifying

        $link['html'] = TRUE;

and using check_plain

$output .= l('<span>'. check_plain($link['title']) .'</span>', $link['href'], $link);

Hope that helps.

aangel’s picture

This helped a lot, thank you. I especially like the drupal_rebuild_theme_registry() tip.

Andre'

Jeff Burnz’s picture

You don't need an extra span tag to do sliding doors, drupal.org tabs are sliding doors with no redundant spans. Over riding the theme function is 100% unnecessary.

See the article regarding this on alistapart - http://www.alistapart.com/articles/slidingdoors2/

KrisBulman’s picture

thanks for this!

Matt Giacomazzo’s picture

This is a really old thread but has come up numerous times when searching on this very topic. I just wanted to say there are advantages to using a span wrapper. This allows to consistent UX when theming :active and :focus states.