Sometimes single section of a site should be customized. Using pathauto correctly can help, but using a menu id can drive to better and more scalable results. I use menu_get_active_trail() to get the id of the active trail.

<?php
  $active_trail
= menu_get_active_trail();
 
$classes[] = zen_id_safe('section-menu-' . $active_trail[1]['mlid']);
?>

A patch is attached.

Files: 
CommentFileSizeAuthor
template_section_menu_class.patch590 byteschirale

Comments

Component:layout.css» PHP Code
Status:Closed (won't fix)» Needs review

I reviewed this patch, (committed manually, sorry) it works flawlessly, this is a welcome feature imho, +1 for me.

Thanks.

Version:6.x-1.0» 6.x-1.1
Component:Code» PHP Code

This is exactly what I'm looking for, but the patch doesn't work for me. It is applied, as I get an additional "section-menu-" added to my body classes, but it failed to identify the active menu trail (it's just "section-menu-", missing the actual menuID). I believe there is an active menu trail on the pages I'm testing, as the "

  • " for the active menu item does have the correct "active_menu" class in place.

    Is there anything I'm missing to add this feature?

  • Hi Michelle,
    this patch is related to Drupal breadcrumb system. To fix the issue on your installation you have to add a module that "fix" the core behaviour on breadcrumb like:

    http://drupal.org/project/menu_breadcrumb

    I've tested this solution and it works fine for more than one installation.

    Thanks chirale. Not sure if it was a caching issue or not (I swear I flushed it multiple times), but now the proper menu-id is appear in the body class for me with this patch. Thanks!

    Component:PHP Code» layout.css
    Status:Needs review» Closed (won't fix)

    This feature is not needed for most sites. I'm glad you were able to figure out a solution for your use-case. :-)

    Status:Needs review» Closed (won't fix)