I have an issue with the "active-trail" class not showing up on <li> for menu items with Drupal 7.14. The problem I have is that "active-trail" is missing for only a menu link to the front page (path "<front>"), all other links have "active-trail" just fine.
The situation is also slightly different for the horizontal primary link tabs that can be switched on from theme settings Toggle display - Main menu, than they are for the vertical navigation in the Main menu block. In the horizontal tabs the front page <li> has "active" but not "active-trail". So "active" could be used to do get around this issue for horizontal menus. But unfortunately I want the vertical menu and in that there is no "active" nor "active-trail".
I also tried different themes and created a new testmenu with a link to the front page with exactly the same problem.
So I suspect this might have something to do with "<front>" not being handled properly?
Is this a bug or a feature of Drupal 7 and has anyone else noticed this? Any suggestions on how to proceed? I tried to search the bug database but did not find this particular issue (this is close but for D6), which is why I thought it best to first ask here.
Comments
I don't think that the
I don't think that the "active-trail" class is generated by Drupal core. The core theme_links() does add an "active" class.
Are you using a module such as Superfish or another menu building module? Does your theme have drop down menus? Maybe the problem is specific to that.
Verified this on 7.4 - 7.14 with all default themes
I verified that both "active" and "active-trail" are missing with a fresh install without any added modules on Drupal 7.4 to 7.14. The behaviour is identical with Bartik, Garland and Stark themes, as well as Zen.
Steps to reproduce:
1. Create a fresh install of Drupal 7.14.
2. On the front page go to Structure -> Blocks.
3. Move "Main menu" block to "First sidebar"
4. Create a new "Basic page" with test content and click "Provide a menu link" -> "Parent item" [Main menu]
5. Use e.g. Firebug to verify that the newly created test page link on the sidebar has "active-trail" on <li> but "Home" does not.
This surely isn't how it's supposed to work? If this is not a bug, can someone help me get around my original problem:
How can I create a .css file that increases the upper and lower margin for the "Home" link in the sidebar "Main menu" when I am on the front page? Because of this issue, there are no class that changes for the "Home" <li> when it is active. I can increase the margins for all the other links that have "active-trail" with:
but not with the "Home" link. Ideas?
Patch attached
So I dug around and found the problem. As I suspected <front> handling was missing. The file was "includes/menu.inc" which I suspect is Drupal core?
This is my first contribution to Drupal, so I don't quite know what is the right way to submit this issue. I suspect I should to create a bug and attach this patch there and hopefully it will get to some future version of D7? The patch below is against the 7.14 tag, should I do it against some other tag/branch?
Drupal Core issue
You need to open an issue in the Drupal Core queue at http://drupal.org/project/issues/drupal
Please restate the summary of the issue and post your fix there.
Perhaps post back that core issue # here to wrap this up.
Drupal core issue created
Thanks for your help!
I created an issue here:
#1578832: [already commited but followup for CR?] <front> menu links are missing active trail classes
Until bug fixed, menu_block is a workaround
As a workaround, until the above bug is fixed, the menu_block module can be used. It adds the "active" class also to <li> which can be used to target the active menu item. However "active-trail" is missing from menu_block menus as well presumably because of the same bug.
theme_menu_link() as workaround
Aigars Matulis
eSoulution
Thank you
Thank you! it's working!!!
Thanks
Thank you for this sollution!
This add class "active", but
This add class "active", but "active-trail" is missing.
another way:
another way:
change the menu link from to node will fix this problem
That probably was supposed to
(That probably was supposed to read "from <front> to node")
But then clicking the front page menu item will end up in www.example.com/node, and on www.example.com the menu item still doesn't have active trail.