I'd like to add classes to <a>
-tags for menu items that have a submenu.
Currently this is my code, I can only add classes to <li>
elements:
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
{% import _self as menus %}
{% if items %}
{% if menu_level == 0 %}
<ul{{ attributes.addClass('nav navbar-nav navbar-right') }}>
{% else %}
<ul class="dropdown-menu panel-collapse collapse">
{% endif %}
{% for item in items %}
{%
set classes = [
item.is_expanded ? 'menu-item--expanded dropdown panel simple-dropdown',
item.is_collapsed ? 'collapsed',
item.in_active_trail ? 'active',
]
%}
<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 %}
</ul>
{% endif %}
{% endmacro %}