How can I theme all the menu levels individually in menu.html.twig?
I need to give different markup to the 2nd (child) and 3rd (grandchild) level, and in the twig I only have parent and child.
{% if item.below %}
{{ menus.menu_links(item.below, attributes.removeClass('nav'), menu_level + 1) }}
{% endif %}
Whatever I put in this is duplicated for the child and grandchildren.
I thought that menu_level + 2
might get it. What does menu_level +
do?
EDIT: Thanks to Hudri's tip below I did the following Thanks Hudri!
{% if menu_level == 0 and item.is_expanded %}
<li{{ item.attributes.addClass(item_classes) }}>
<a href="{{ item.url }}" class="dropdown-toggle nav__title" data-target="" data-toggle="dropdown">{{ item.title }} </a>
{% elseif menu_level == 1 %}
<li{{ item.attributes.addClass(item_classes) }}>
{{
link(
item.title,
item.url,
item.attributes.removeClass(item_classes),
item.attributes.setAttribute('title', '')
)
}}
{% elseif menu_level == 2 %}
<li{{ item.attributes.addClass(item_classes) }}>
{{
link(
item.title,
item.url,
item.attributes
)
}}