Been trying for a while to solve this in drupal but have never found a good solution.

What I'm trying to do is to say to drupal that this node (or node-type) is related to this menu-item (for example news).

So when i create a new node (of the type: news) the active class should be put on the News item so you know which section you are visiting.

I been using menutrails for some sites but it's a very strange module that only works from time to time.

Found a function in drupal that is called menu_set_location (http://api.drupal.org/api/function/menu_set_location/59 that sound exactly what I'm trying to do.

Frequently, modules may want to make a page or node act as if it were in the menu tree somewhere, even though it was not registered in a hook_menu() implementation. If the administrator has rearranged the menu, the newly set location should respect this in the breadcrumb trail and expanded/collapsed status of menu items in the tree. This function allows this behavior.

But I can't figure out how to use this function correctly, could someone give me a kick start on how to use this right?

Comments

arh1’s picture

good question. for me, it's the best way to mark a menu item as "active" (i.e. add the 'active' class to the <li> and/or <a>) in an arbitrary circumstance. e.g. if a i have a tier2 menu that's a separate Drupal menu from the tier1 menu, and i want to set the appropriate tier1 item to be active when a page in the tier2 menu is selected.

to date, i've relied on pretty hacky solutions at the theme layer: a custom function in template.php that does things like parse the url looking for a /tier1/tier2 type of pattern.

i didn't know about the menu_set_location function (correct link: http://api.drupal.org/api/function/menu_set_location/5 ). that looks interesting. doesn't look like the function exists in Drupal 6, though. maybe some of the other menu-related functions in 6 will do something similar.