Hello,

maybe someone could give me an advice on this or point me to some already existing thread...

I have a block-topmenu.tpl.php and I need to have access to the menuitems for css-tagging them individuallly,
like

<li class ="leaf leaf1" ... />
<li class ="leaf leaf2" ... />

Is there a proper solution instead of "parsing" the $block->content

Comments

styro’s picture

Theme overrides:
http://drupal.org/node/173880

This is most probably the themable function you'll want to override:
http://api.drupal.org/api/function/theme_menu_item/6

--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal

raslam’s picture

Hi,

I have kinda similar problem and i'm using Drupal 6.2. I know the themable functions which we can override. But problem is these functions override menu items of all menus. Whereas, i'm currently stuck in a situation where I have top and left navigation. All I want to do is assign a particular ID to top nav <ul> list and a particular class to its <li> items. I'm currently trying with theme_menu_tree($tree) function to override. Then there is menu_tree($pid) function which I can use to check my menu ID. But I can't find the $pid for my menu. This $pid doesn't come up in the source too.

I am porting an existing template to drupal so I have limitation adding new styles to the theme. Otherwise I would have done it easily.

Thanks and looking forward.

Rashid Aslam
Aspire Solutions

styro’s picture

Then there is menu_tree($pid) function which I can use to check my menu ID. But I can't find the $pid for my menu. This $pid doesn't come up in the source too.

On the menu admin page, hover over the edit menu item links - the menu id will be in the edit url.

Note: some menu functions use the parent items menu id. The root menu id is 0 from memory.

--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal

tasc’s picture

For now I'm using the following solution, where "clean" is my theme:

  
function getMenuItemCounter($case=null){
  static $counter = 1;
  return ($case == 'reset') ? $counter=1 : $counter++ ;
}

// theme_menu_tree()
function clean_menu_tree($tree) {
  getMenuItemCounter("reset");
  return '<ul class="menu">'. $tree .'</ul>';
}

// theme_menu_item()
function clean_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
  $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty($extra_class)) {
    $class .= ' '. $extra_class;
  }
  if ($in_active_trail) {
    $class .= ' active-trail';
  }
  $counter = getMenuItemCounter();
  $class .= " item_".$counter;
  return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
}
  

Now all menu_items are tagged, which I can live with.
Any hint of theming a menu residing in a specific block is much appreciated,
any info on where I could define this $extra_class as well !

(With dhtml- menu -module you'll have to "theme" their functions, it's a bit tricky though)

drupalgeek’s picture