{% 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) %} {%- 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(['dropdown-submenu']) %} {% 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 = ['list-unstyled', 'collapse'] %} {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' '),'id': 'collapse-subnav-' ~ item.name }) %} {{ block('list') }} {% endif %} {% endblock %} {% block linkElement %} {% import 'knp_menu.html.twig' as macroattr %} {%- set linkAttributes = item.linkAttributes|merge({ 'class': 'nav-link'}) %} {{ block('label') }} {% if item.hasChildren and item.level is not same as(0) and item.displayChildren %}{%- endif %} {% if item.hasChildren and item.level is not same as(0) and item.displayChildren %} {%- endif %} {% endblock %} {% block children %} {# save current variables #} {% set currentOptions = options %} {% set currentItem = item %} {# update the depth for children #} {% if options.depth is not none %} {% set options = options|merge({'depth': currentOptions.depth - 1}) %} {% endif %} {# update the matchingDepth for children #} {% if options.matchingDepth is not none and options.matchingDepth > 0 %} {% set options = options|merge({'matchingDepth': currentOptions.matchingDepth - 1}) %} {% endif %} {% for item in currentItem.children %} {{ block('item') }} {% endfor %} {# restore current variables #} {% set item = currentItem %} {% set options = currentOptions %} {% endblock %}