By phl3tch on
Hi all --
I need to change the class of a specific menu in order to not trigger DHTML Menus for that menu. I know I can fiddle with this:
function theme_menu_tree($tree) {
return '<ul class="menu">'. $tree .'</ul>';
}But that affects all menus. Is there some way in the context of this function to determine something about $tree -- i.e. which menu it is?
Or perhaps some other route?
Comments
Alright, I must be the only
Alright, I must be the only person ever to have wondered about this. I've posted two variations on this issue and received a collective shrug both times.
Well, I spent a large part of the weekend investigating, and for the benefit of those few that might also have a problem with how this works, here's what I've found. First let me reiterate a little background: I want DHTML Menus to target specific menus, but it targets everything with the "menu" class.
Ok, so 1) when the menu module fires it's block hook, in the event of a block containing a menu, it calls menu_tree with the name of the menu to be rendered.
2) Menu_tree grabs the menu data and calls menu_tree_output with the tree data.
3) Menu_tree_output runs each li element through the relevant theme function and then passes the whole mess to theme_menu_tree.
4) Theme_menu_tree wraps the list with a ul element, classed "menu."
It's certainly possible to change theme_menu_tree and specify a different class, or an id, or whatever you want. However, since the only data that theme_menu_tree receives is the tree itself, there's no reasonable way to theme the menu dynamically. How lovely it would be if the theme function received, say, the tree and the menu name. But no.
So my solutions at this point consist of:
1) Use regex to change the class in a block template,
2) Use javascript to change the class in the page template before dhtml_menus.js runs, or
3) Write alternate versions of menu_tree and menu_tree_output, as well as the theming functions, and run them from the block template. This would mean the menu would be rendered the normal way and discarded in favor of this second rendering. Kind of a waste.
Unfortunately I had to do one of them. So I chose #3. It works ok, but feels hacky to me. If anyone has a better alternative, please post it here.
You are not the only one, though I fear I cannot help.
Thanks CrackWildling.
I have nothing else to offer, but I am also looking to add an additional class to the <ul> of a particular menu, as well as to add extra html on each navigation item. I've themed theme_menu_item in my template.php file. This allows me to add things within each <li class="leaf">...</li>, but I can't, for the life of me, find a variable to apply conditional logic. I want to say: "If the menu in question is $menu name do this code."
My problem is that I don't know how to expose the name of the menu (or even where to get that information) to my template.php file. Theme_menu_tree()'s variable, $menu_name, appears to become a huge array, no? I'd love to contain the logic in template.php so it doesn't feel "hacky," but I'm not a coder so maybe I'm overreaching.
Anyone out there know how to get template.php to say "oh - THIS menu" and expose all of it's markup and logic?
This is a huge pain in the
This is a huge pain in the butt. I simply did a str_replace on the $tree variable:
This is relatively fool-proof since no one's gonna make a menu item called "class="menu"". Still, I hate doing stuff like this...
Same issue
Well the drupal proudly says that for theming you dont need php experience a lot. Theming menus has proved it wrong.
It seems there is no simple way to change a class of menu.
They should have given one more variable for class in the function:
theme('links', menu_navigation_links('menu-blog-header',0,'class-name'));
Unfortunately this is not possible :(