templates/Menu/knp_menu.html.twig line 1

Open in your IDE?
  1. {% extends 'knp_menu_base.html.twig' %}
  2. {% set currentClass = options.currentClass ?? 'active' %}
  3. {% macro attributes(attributes) %}
  4.     {% for name, value in attributes %}
  5.         {%- if value is not none and value is not same as(false) -%}
  6.             {{- ' %s="%s"'|format(name, value is same as(true) ? name|e : value|e)|raw -}}
  7.         {%- endif -%}
  8.     {%- endfor -%}
  9. {% endmacro %}
  10. {% block compressed_root %}
  11.     {% apply spaceless %}
  12.         {{ block('root') }}
  13.     {% endapply %}
  14. {% endblock %}
  15. {% block root %}
  16.     {% set listAttributes = item.childrenAttributes %}
  17.     {{ block('list') -}}
  18. {% endblock %}
  19. {# list renders listing of menu object #}
  20. {% block list %}
  21.     {% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %}
  22.         {{ block('children') }}
  23.     {% endif %}
  24. {% endblock %}
  25. {# children renders childrens of object #}
  26. {% block children %}
  27.     {# save current variables #}
  28.     {% set currentOptions = options %}
  29.     {% set currentItem = item %}
  30.     {# update the depth for children #}
  31.     {% if options.depth is not none %}
  32.         {% set options = options|merge({'depth': currentOptions.depth - 1}) %}
  33.     {% endif %}
  34.     {# update the matchingDepth for children #}
  35.     {% if options.matchingDepth is not none and options.matchingDepth > 0 %}
  36.         {% set options = options|merge({'matchingDepth': currentOptions.matchingDepth - 1}) %}
  37.     {% endif %}
  38.     {% for item in currentItem.children %}
  39.         {{ block('item') }}
  40.     {% endfor %}
  41.     {# restore current variables #}
  42.     {% set item = currentItem %}
  43.     {% set options = currentOptions %}
  44. {% endblock %}
  45. {# item renders object of elements #}
  46. {% block item %}
  47.     {% if item.displayed and item.attributes.enabled %}
  48.         {# building the class of the item #}
  49.         {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  50.         {%- if matcher.isCurrent(item) %}
  51.             {%- set classes = classes|merge([currentClass]) %}
  52.         {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  53.             {%- set classes = classes|merge([options.ancestorClass]) %}
  54.         {%- endif %}
  55.         {%- if item.actsLikeFirst %}
  56.             {%- set classes = classes|merge([options.firstClass]) %}
  57.         {%- endif %}
  58.         {%- if item.actsLikeLast %}
  59.             {%- set classes = classes|merge([options.lastClass]) %}
  60.         {%- endif %}
  61.         {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
  62.         {% if item.hasChildren and options.depth is not same as(0) %}
  63.             {% if options.branch_class is not empty and item.displayChildren %}
  64.                 {%- set classes = classes|merge([options.branch_class]) %}
  65.             {% endif %}
  66.         {% elseif options.leaf_class is not empty %}
  67.             {%- set classes = classes|merge([options.leaf_class]) %}
  68.         {%- endif %}
  69.         {%- set attributes = item.attributes %}
  70.         {%- if classes is not empty %}
  71.             {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  72.         {%- endif %}
  73.         {# displaying the item #}
  74.         {% import _self as knp_menu %}
  75.         {%- if item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  76.             {{ block('linkElement') }}
  77.         {%- elseif 'section' == item.attributes.menuType %}
  78.             {{ block('sectionElement') }}
  79.         {%- else %}
  80.             {{ block('spanElement') }}
  81.         {%- endif %}
  82.         {# render the list of children #}
  83.         {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  84.         {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
  85.         {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  86.         {{ block('list') }}
  87.     {% endif %}
  88. {% endblock %}
  89. {# LinksElements Shows Elements with no childrens #}
  90. {% block linkElement %}
  91.     {% import _self as knp_menu %}
  92.     {%- set classes = item.linkAttribute('class') is not empty ? [item.linkAttribute('class')] : [] %}
  93.     {%- if matcher.isCurrent(item) %}
  94.         {%- set classes = classes|merge([currentClass]) %}
  95.     {%- endif %}
  96.     {%- set attributes = item.linkAttributes %}
  97.     {%- if classes is not empty %}
  98.         {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  99.     {%- endif %}
  100.     {% if item.level < 2 %}
  101.         <div class="menu-item">
  102.             <a {{ knp_menu.attributes(attributes) }} href="{{ item.uri }}">
  103.                 <span class="menu-icon">
  104.                     {% if item.attribute('icon') is not empty %}
  105.                         <span class="svg-icon svg-icon-2">
  106.                             <i class="{{ item.attribute('icon') }}"></i>
  107.                         </span>
  108.                     {% endif %}
  109.                 </span>
  110.                 <span class="menu-title">{{ block('label')}}</span>
  111.             </a>
  112.         </div>
  113.     {% endif %}
  114. {% endblock %}
  115. {# spanElement Shows Elements with childrens #}
  116. {% block spanElement %}
  117.     {% import _self as knp_menu %}
  118.     {% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %}
  119.         {% import _self as knp_menu %}
  120.         {%- set classes = item.linkAttribute('class') is not empty ? [item.linkAttribute('class')] : [] %}
  121.         {%- if matcher.isCurrent(item) %}
  122.             {%- set classes = classes|merge([currentClass]) %}
  123.         {%- endif %}
  124.         {%- set attributes = item.linkAttributes %}
  125.         {%- if classes is not empty %}
  126.             {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  127.         {%- endif %}
  128.         {% set subItemUri = [] %}
  129.         {% for subItem in item.children %}
  130.             {% set subItemUri = subItemUri|merge([subItem.uri]) %}
  131.         {% endfor %}
  132.         <div data-kt-menu-trigger="click" class="menu-item menu-accordion {% if item.current %}hover show{% elseif app.request.pathinfo in subItemUri %}hover show{% endif %}">
  133.             <span class="menu-link">
  134.                 <span class="menu-icon">
  135.                     {% if item.attribute('icon') is not empty %}
  136.                         <span class="svg-icon svg-icon-2">
  137.                             <i class="{{ item.attribute('icon') }}"></i>
  138.                         </span>
  139.                     {% endif %}
  140.                 </span>
  141.                 <span class="menu-title">{{ block('label') }}</span>
  142.                 <span class="menu-arrow"></span>
  143.             </span>
  144.             <div class="menu-sub menu-sub-accordion {% if item.current %}hover show{% elseif app.request.pathinfo in subItemUri %}hover show{% endif %}">
  145.                 {% for subItem in item.children %}
  146.                     {% if subItem.displayChildren and subItem.attributes.enabled %}
  147.                         <div class="menu-item">
  148.                             <a class="menu-link {{subItem.attributes.class}} {% if subItem.uri == app.request.pathinfo %}active{% endif %}" href="{{ subItem.uri }}">
  149.                                 <span class="menu-icon">
  150.                                     {% if subItem.attribute('icon') is not empty %}
  151.                                         <span class="svg-icon svg-icon-2">
  152.                                             <i class="{{ subItem.attribute('icon') }}"></i>
  153.                                         </span>
  154.                                     {% endif %}
  155.                                 </span>
  156.                                 <span class="menu-title">{{ subItem.label }}</span>
  157.                             </a>
  158.                         </div>
  159.                     {% endif %}
  160.                 {% endfor %}
  161.             </div>
  162.         </div>
  163.     {% endif %}
  164. {% endblock %}
  165. {# section renders sections of elements #}
  166. {% block sectionElement %}
  167.     <div class="menu-item pt-5">
  168.         <div class="menu-content">
  169.             <span class="menu-heading fw-bold text-uppercase fs-7">{{ block('label')}}</span>
  170.         </div>
  171.     </div>
  172. {% endblock %}
  173. {# label renders labels of elements #}
  174. {% block label %}
  175.     {# {% if options.allow_safe_labels and item.getExtra('safe_label', false) %} #}
  176.         {{ item.label|raw }}
  177.     {# {% else %}
  178.         {{ item.label }}
  179.     {% endif %} #}
  180. {% endblock %}