Hi. First time user here. I'm using this module (2.0.0) with Drupal 10.0.9.
I created a new theme using starterkit (php core/scripts/drupal generate-theme mythemename
) and cannot seem to get this module to have any effect on the output HTML.
My setup is very simple:
- a "News" content type with automatic aliases of /news/title-nid
- a /news page (views) which show the news items
- a "News" menu item that I have manually created (it's not generated by views) and points to the /news page.
When I visit the "News" page (/news), the "News" menu item is highlighted as expected.
However when I visit the a news item (/news/title-nid), the menu item is not highlighted.
The module is configured to use "By Path" as a trail source, and I tested several values for the "Maximum path parts" (including 0). I emptied Drupal's cache each time.
I did notice that the homepage for the module writes "Drupal 8 - Make sure to use a "menu.html.twig" like the classy-theme (or use that as base theme, like bartik does), stable-theme and stark-theme will not add the classes that you propably will expect, see
"No active trail class gets added"-issue." →
and I read the related issue.
However it's a 7 years-old issue and I don't know if it's still relevant for Drupal 10...
I checked the templates of my child theme, more specifically templates/navigation/menu.html.twig
and here is what I see:
{% for item in items %}
{%
set classes = [
'menu-item',
item.is_expanded ? 'menu-item--expanded',
item.is_collapsed ? 'menu-item--collapsed',
item.in_active_trail ? 'menu-item--active-trail',
]
%}
<li{{ item.attributes.addClass(classes) }}>
{{ link(item.title, item.url) }}
{% if item.below %}
{{ menus.menu_links(item.below, attributes, menu_level + 1) }}
{% endif %}
</li>
{% endfor %}
It seems to me that the class that I need (menu-item--active-trail) is indeed present in this theme.
Classy or Bartik aren't present in Drupal 10 core any more, so I couldn't check what their templates look like.
What am I doing wrong?