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.
Menu item does not have "active" class when the menu item page is open.
Comment | File | Size | Author |
---|---|---|---|
#10 | bootstrap-add-active-class-to-menu-item-2643538-10.patch | 2.82 KB | seworthi |
Comments
Comment #2
markhalliwellPatches are welcomed.
Comment #3
markhalliwellComment #4
CRZDEV CreditAttribution: CRZDEV at Metadrop commentedDrupal core adds the active class into links through javascript (located in /core/misc/active-link.js) using the data-attribute "data-drupal-link-system-path" with the referenced path value.
Bootstrap wants the active class in the menu item element
<li>
, there are two ways to solve this;- One would be using js, adding the link class to the menu item parent element.
- Other consists into adding class into menu preprocess function:
And adding it into twig template:
But this way it only works into first menu level, is needed to deep into each menu item and search for other menus (recursively).
Any suggestions?
Comment #5
Macronomicus CreditAttribution: Macronomicus commentedThis can be done with twig too, after some investigation and tweaking for bootstrap theme I got it to work, might need more cleanup YMMV :)
Copy menu--main.html.twig from the bootstrap theme and add to your subthemes templates folder with the following changes.
Also you'll need the .menu-item--active-trail bit in your css, so if items in the dropdown are active sets the parent trail as active too.
Comment #6
davy-r CreditAttribution: davy-r commentedI received a bug report "It doesn't work with Bootstrap", for the Menu Trail By Path module, which lead me to this issue.
I created a patch based on the idea of #5.
Comment #7
csedax90 CreditAttribution: csedax90 commentedPatch #6 works like a charm
Comment #8
vistree CreditAttribution: vistree commentedPatch in #6 works great - an absolute need!!!
Comment #9
kevinwal CreditAttribution: kevinwal at KWALL commented#6 works great. Thanks!
Comment #10
seworthi CreditAttribution: seworthi at Estrella Mountain Community College commentedFixed formatting of set command to match style in other bootstrap templates.
Works great.
Comment #11
jorgediazhav CreditAttribution: jorgediazhav at Evolving Web commentedWorks pretty well.
Comment #13
markhalliwellComment #15
lukasss CreditAttribution: lukasss commentedRight now I have not worked it!
I do so:
1) Install drupal 8
2) Enable view "glossary"
3) drush dl bootstrap
4) Set as default bootstrap theme
3) When I visit "glossary", I see:
Only when I add a link to "/glossary" on page /admin/structure/menu/manage/main/add I see:
I don't know if this related problem with Tim's question or views?
Comment #16
TLWatson@lukasss - I am having the same problem, specifically for a Glossary view. I believe it's related to this issue, not Bootstrap:
https://www.drupal.org/node/2820751