Skip to main content

Context Module provides method active trail menu by content type

Submitted by callum on 30 May 2012
work drupal

Once of the challenges I have found when using views is maintaining the menu active trail classes through the view listings to the content nodes themselves.

For example you have a news home page which lists all the nodes of content type 'news' with a link to the full article. The view is either a page, or a block added to a page, both of  which can then be added to the menu. When on the listing page, the menu item gains the active trail classes as required. But as soon as you go to the full news item, Drupal is not aware that the menu item should retain the active trail classes and all navigation visual clues have now gone.

My solutions have ranged from:

  • adding a themename_menu_link function;
  • using CSS Injector along with Path Auto. Set the content type to be located on path pattern, for example /news/yyyy/mm/title. The css is then dropped into the path '/news' and styles the appropriate menu item to the active state. But this required the use of unique ids and can fall over if the menu is changed;
  • using the Drupal defined body classes to achieve the same result as above;

But I have just seen this:

Context, which provides a mechanism to set up rules to provide the active trail classes to menu items based on content type. It does a LOT more as well, such as show / hide regions based on rules you can define. there is a nice over view on mustardseedmedia.

But it's sorted out my menu structure, properly, and that makes me happy :)