{% extends 'knp_menu.html.twig' %} {% block item %} {% import 'knp_menu.html.twig' as macroattr %} {% if item.displayed %} {# building the class of the item #} {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %} {%- if matcher.isCurrent(item) %} {%- set classes = classes|merge([options.currentClass]) %} {%- elseif matcher.isAncestor(item, options.matchingDepth) %} {%- set classes = classes|merge([options.ancestorClass]) %} {%- endif %} {%- if item.actsLikeFirst %} {%- set classes = classes|merge([options.firstClass]) %} {%- endif %} {%- if item.actsLikeLast %} {%- set classes = classes|merge([options.lastClass]) %} {%- endif %} {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #} {% if item.hasChildren and options.depth is not same as(0) %} {%- set classes = classes|merge(['dropdown']) %} {% if options.branch_class is not empty and item.displayChildren %} {%- set classes = classes|merge([options.branch_class]) %} {% endif %} {% elseif options.leaf_class is not empty %} {%- set classes = classes|merge([options.leaf_class]) %} {%- endif %} {%- set attributes = item.attributes %} {%- if classes is not empty %} {%- set attributes = attributes|merge({'class': classes|join(' ')}) %} {%- endif %} {# displaying the item #} {%- if item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %} {{ block('linkElement') }} {%- else %} {{ block('spanElement') }} {%- endif %} {# render the list of children#} {%- set childrenClasses = ['menu_level_' ~ item.level, 'dropdown-menu'] %} {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %} {{ block('list') }} {% endif %} {% endblock %} {% block linkElement %} {% import 'knp_menu.html.twig' as macroattr %} {% if item.hasChildren and item.level is same as(1) and item.displayChildren %} {%- set linkAttributes = item.linkAttributes|merge({ 'class': 'dropdown-toggle nav-link', 'data-toggle': 'dropdown', 'aria-haspopup': 'true', 'aria-expanded': 'false'}) %} {%- else %} {%- set linkAttributes = item.linkAttributes %} {%- endif %} {{ block('label') }} {% if item.hasChildren and item.level is same as(1) and item.displayChildren %} {%- endif %} {% endblock %}