templates/menu/knp_menu.html.twig line 1

Open in your IDE?
  1. {% extends 'knp_menu.html.twig' %}
  2. {% block list %}
  3.     {% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %}
  4.         {% import _self as knp_menu %}
  5.         {% set listAttributes = listAttributes|merge({class: (listAttributes.class|default('') ~ ' nav-menu level-' ~ (item.level < 0 ? 0 : item.level - 1))}) %}
  6.         {% if item.children|length > 0 and item.level > 0 %}
  7.             {% set listAttributes = listAttributes|merge({class: (listAttributes.class|default('') ~ ' nav-child')}) %}
  8.             <div class="collapse" id="collapse-{{ item.name|lower|slug }}" data-parent="#main-menu">
  9.                 <ul{{ knp_menu.attributes(listAttributes) }}>
  10.                     {{ block('children') }}
  11.                 </ul>
  12.             </div>
  13.         {% else %}
  14.             <ul{{ knp_menu.attributes(listAttributes) }}>
  15.                 {{ block('children') }}
  16.             </ul>
  17.         {% endif %}
  18.     {% endif %}
  19. {% endblock %}
  20. {% block item %}
  21.     {% if item.displayed %}
  22.         {# building the class of the item #}
  23.         {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  24.         {%- if matcher.isCurrent(item) %}
  25.             {%- set classes = classes|merge([options.currentClass]) %}
  26.         {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  27.             {%- set classes = classes|merge([options.ancestorClass]) %}
  28.         {%- endif %}
  29.         {%- if item.actsLikeFirst %}
  30.             {%- set classes = classes|merge([options.firstClass]) %}
  31.         {%- endif %}
  32.         {%- if item.actsLikeLast %}
  33.             {%- set classes = classes|merge([options.lastClass]) %}
  34.         {%- endif %}
  35.         {% set classes = classes|merge(['nav-item']) %}
  36.         {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
  37.         {% if item.hasChildren and options.depth is not same as(0) %}
  38.             {% if options.branch_class is not empty and item.displayChildren %}
  39.                 {%- set classes = classes|merge([options.branch_class]) %}
  40.             {% endif %}
  41.         {% elseif options.leaf_class is not empty %}
  42.             {%- set classes = classes|merge([options.leaf_class]) %}
  43.         {%- endif %}
  44.         {%- set attributes = item.attributes %}
  45.         {%- if classes is not empty %}
  46.             {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  47.         {%- endif %}
  48.         {# displaying the item #}
  49.         {% import _self as knp_menu %}
  50.         {% set item_attr = attributes|filter((value, key) => key != 'icon') %}
  51.         <li{{ knp_menu.attributes(item_attr) }}>
  52.             {%- if item.children|length > 0 -%}
  53.                 {{ block('collapseElement') }}
  54.             {%- elseif item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  55.                 {{ block('linkElement') }}
  56.             {%- else %}
  57.                 {{ block('spanElement') }}
  58.             {%- endif %}
  59.             {# render the list of children #}
  60.             {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  61.             {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  62.             {{ block('list') }}
  63.         </li>
  64.     {% endif %}
  65. {% endblock %}
  66. {% block collapseElement %}
  67.     {% import _self as knp_menu %}
  68.     {% set collapse_attributes = item.labelAttributes %}
  69.     {% if item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  70.         {% set collapse_attributes = item.linkAttributes %}
  71.     {% endif %}
  72.     {% set additional_class = 'nav-link level-' ~ (item.level < 0 ? 0 : item.level - 1) ~ ' collapsed' ~ (matcher.isAncestor(item, options.matchingDepth) ? ' current-ancestor': '') %}
  73.     {% set collapse_attributes = collapse_attributes|merge({class: (collapse_attributes.class|default('') ~ additional_class)}) %}
  74.     <a href="#collapse-{{ item.name|lower|slug }}" data-bs-toggle="collapse" {{ knp_menu.attributes(collapse_attributes) }}>
  75.         {{ block('label') }}
  76.     </a>
  77. {% endblock %}
  78. {% block linkElement %}
  79.     {% import _self as knp_menu %}
  80.     {% set element_attributes = item.linkAttributes %}
  81.     {% set additional_class = 'nav-link level-' ~ (item.level < 0 ? 0 : item.level - 1) ~ (matcher.isCurrent(item) ? ' active' : '') ~ (matcher.isAncestor(item, options.matchingDepth) ? ' current-ancestor': '') %}
  82.     {% set element_attributes = element_attributes|merge({class: (element_attributes.class|default('') ~ additional_class)}) %}
  83.     <a href="{{ item.uri }}"{{ knp_menu.attributes(element_attributes) }}>
  84.         {{ block('label') }}
  85.     </a>
  86. {% endblock %}
  87. {% block spanElement %}
  88.     {% import _self as knp_menu %}
  89.     {% set element_attributes = item.labelAttributes %}
  90.     {% set additional_class = 'nav-link level-' ~ (item.level < 0 ? 0 : item.level - 1) ~ (matcher.isCurrent(item) ? ' active' : '') ~ (matcher.isAncestor(item, options.matchingDepth) ? ' current-ancestor': '') %}
  91.     {% set element_attributes = element_attributes|merge({class: (element_attributes.class|default('') ~ additional_class)}) %}
  92.     <span{{ knp_menu.attributes(element_attributes) }}>
  93.         {{ block('label') }}
  94.     </span>
  95. {% endblock %}
  96. {% block label %}
  97.     {% if item.attributes.icon is defined %}
  98.         <span class="nav-icon mai">{{ item.attributes.icon }}</span>
  99.     {% endif %}
  100.     <span class="nav-content">
  101.         <span class="nav-text">
  102.             {% if options.allow_safe_labels and item.getExtra('safe_label', false) %}
  103.                 {{ item.label|raw }}
  104.             {% else %}
  105.                 {{ item.label }}
  106.             {% endif %}
  107.         </span>
  108.         {% if item.children|length > 0 %}
  109.             <span class="mai mai-chevron">expand_more</span>
  110.         {% else %}
  111.             <span class="mai mai-arrow">arrow_forward</span>
  112.         {% endif %}
  113.     </span>
  114. {% endblock %}