Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
$active_trail = menu_get_active_trail();
$classes[] = zen_id_safe('section-menu-' . $active_trail[1]['mlid']);
A patch is attached.
Comment | File | Size | Author |
---|---|---|---|
template_section_menu_class.patch | 590 bytes | chirale |
Comments
Comment #1
keesje CreditAttribution: keesje commentedI reviewed this patch, (committed manually, sorry) it works flawlessly, this is a welcome feature imho, +1 for me.
Thanks.
Comment #2
michellezeedru CreditAttribution: michellezeedru commentedThis 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 "
Is there anything I'm missing to add this feature?
Comment #3
chirale CreditAttribution: chirale commentedHi 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.
Comment #4
michellezeedru CreditAttribution: michellezeedru commentedThanks 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!
Comment #5
JohnAlbinThis feature is not needed for most sites. I'm glad you were able to figure out a solution for your use-case. :-)