Summary
The menu--main.html.twig template hardcodes class="nav-link" (and class="dropdown-item" for submenus) on menu link <a> tags, ignoring any custom link classes set via the menu_link_attributes module.
Steps to reproduce
- Enable the
menu_link_attributes module (ships with DXPR CMS)
- Edit a main menu link and add a Link class such as
btn btn-primary
- The class is stored correctly in the link options:
{"attributes":{"class":["btn","btn-primary"]}}
- However, the rendered HTML outputs only
class="nav-link" — the custom classes are lost
Root cause
In menu--main.html.twig, the link element is built with a literal class attribute:
{# Line ~109: Simple top-level item #}
<{{ item_link_tag }}
class="nav-link"
...
role="menuitem">{{ item.title }}</{{ item_link_tag }}>
The URL's options/attributes (which carry the menu_link_attributes classes) are never merged into the <a> tag. This pattern repeats for all link types in the template (split dropdown, full toggle, submenu items).
Expected behavior
Custom link classes from menu_link_attributes should be merged with the base classes. For example, a CTA button in the nav should render as:
<a class="nav-link btn btn-primary" href="/shop" role="menuitem">Pre-order</a>
Suggested fix
Use item.url.getOption('attributes') in the template to merge custom attributes, similar to how item.attributes is used on the <li> element for container_class.
Environment
- DXPR Theme: latest (1.x branch)
- Drupal: 11.3.5
- menu_link_attributes: enabled
Summary
The
menu--main.html.twigtemplate hardcodesclass="nav-link"(andclass="dropdown-item"for submenus) on menu link<a>tags, ignoring any custom link classes set via themenu_link_attributesmodule.Steps to reproduce
menu_link_attributesmodule (ships with DXPR CMS)btn btn-primary{"attributes":{"class":["btn","btn-primary"]}}class="nav-link"— the custom classes are lostRoot cause
In
menu--main.html.twig, the link element is built with a literal class attribute:The URL's options/attributes (which carry the
menu_link_attributesclasses) are never merged into the<a>tag. This pattern repeats for all link types in the template (split dropdown, full toggle, submenu items).Expected behavior
Custom link classes from
menu_link_attributesshould be merged with the base classes. For example, a CTA button in the nav should render as:Suggested fix
Use
item.url.getOption('attributes')in the template to merge custom attributes, similar to howitem.attributesis used on the<li>element forcontainer_class.Environment