Enhancing Drupal Menus: Integrating Title, Classes, and Rel Attributes with Menu Link and Link Attributes Modules

Created on 6 February 2024, 10 months ago
Updated 27 June 2024, 5 months ago

I tried to use the modules Menu_link_attributes and Menus_attribute to add classes to menu items and menu links, but the the classes and IDs I added didn't show up in the HTML output.

I suppose this because the theme doesn't take into account existing attributes before setting them, similarly to what Olivero did.

Here is the related issue and its resolution:
https://www.drupal.org/project/menu_link_attributes/issues/3193364
https://github.com/yannickoo/menu_link_attributes/issues/19

For the classes, the solution looks like adding this after setting the classes :

{% if item.url.getOption('attributes').class is not null %}
  {% set link_classes = link_classes|merge([item.url.getOption('attributes').class]) %}
{% endif %}

Can this mechanism please be implemented for the relevant attributes, such as classes, IDs, ... on menu items, links ?

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024