templates/menu/main_menu.html.twig line 1

Open in your IDE?
  1. {% extends '@KnpMenu/menu.html.twig' %}
  2. {% block icon %}
  3.     {%- set icon = item.extra('icon') %}
  4.     {%- set flex = item.extra('flex') %}
  5.     {%- if icon %}
  6.         {%- if flex %}<span class="d-flex">{%- endif %}
  7.     {%- if flex %}<span class="position-relative">{{ block('badge') }}{%- endif %}
  8.         <i class="{{ icon }} bi-fw"></i>
  9.     {%- if flex %}</span>{%- endif %}
  10.         {%- if flex %}</span>{%- endif %}
  11.     {%- endif %}
  12. {% endblock %}
  13. {% block badge %}
  14.     {%- set badge = item.extra('badge') %}
  15.     {%- set badge_classes = item.extra('badge_class') %}
  16.     {%- if badge %}
  17.         <span class="badge rounded-pill {{ badge_classes }}">{{ badge }}</span>
  18.     {%- endif %}
  19. {% endblock %}
  20. {% block list %}
  21.     {% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %}
  22.         {% import _self as knp_menu %}
  23.         <div class="menu-item-group" {{ knp_menu.attributes(listAttributes) }}>
  24.             {{ block('children') }}
  25.         </div>
  26.     {% endif %}
  27. {% endblock %}
  28. {% block item %}
  29.     {% if item.displayed %}
  30.         {# building the class of the item #}
  31.         {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  32.         {%- if matcher.isCurrent(item) %}
  33.             {%- set classes = classes|merge([options.currentClass]) %}
  34.         {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  35.             {%- set classes = classes|merge([options.ancestorClass]) %}
  36.         {%- endif %}
  37.         {%- if item.actsLikeFirst %}
  38.             {%- set classes = classes|merge([options.firstClass]) %}
  39.         {%- endif %}
  40.         {%- if item.actsLikeLast %}
  41.             {%- set classes = classes|merge([options.lastClass]) %}
  42.         {%- endif %}
  43.         {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
  44.         {% if item.hasChildren and options.depth is not same as(0) %}
  45.             {% if options.branch_class is not empty and item.displayChildren %}
  46.                 {%- set classes = classes|merge([options.branch_class]) %}
  47.             {% endif %}
  48.         {% elseif options.leaf_class is not empty %}
  49.             {%- set classes = classes|merge([options.leaf_class]) %}
  50.         {%- endif %}
  51.         {%- set attributes = item.attributes %}
  52.         {%- if classes is not empty %}
  53.             {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  54.         {%- endif %}
  55.         {# displaying the item #}
  56.         {% import _self as knp_menu %}
  57.         <span {{ knp_menu.attributes(attributes) }}>
  58.             {%- if item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  59.                 {{ block('linkElement') }}
  60.             {%- else %}
  61.                 {{ block('spanElement') }}
  62.             {%- endif %}
  63.             {# render the list of children#}
  64.             {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  65.             {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
  66.             {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  67.             {{ block('list') }}
  68.         </span>
  69.     {% endif %}
  70. {% endblock %}
  71. {% block linkElement %}
  72.     {% import _self as knp_menu %}
  73.     {%- set classes = item.linkAttribute('class') is not empty ? [item.linkAttribute('class')] : [] %}
  74.     {%- if matcher.isCurrent(item) %}
  75.         {%- set classes = classes|merge([options.currentClass]) %}
  76.     {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  77.         {%- set classes = classes|merge([options.ancestorClass]) %}
  78.     {%- endif %}
  79.     {%- set attributes = item.linkAttributes %}
  80.     {%- if classes is not empty %}
  81.         {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  82.     {%- endif %}
  83.     {%- set flex = item.extra('flex') %}
  84.     <a href="{{ item.uri }}"{{ knp_menu.attributes(attributes) }}>
  85.         {{ block('icon') }}
  86.         {%- if flex %}<span class="d-flex">{%- endif %}
  87.             {{ block('label') }}
  88.             {%- if flex %}</span>{%- endif %}
  89.         {%- if not flex %}{{ block('badge') }}{%- endif %}
  90.     </a>
  91. {% endblock %}