src/Front/Templates/Menu/menu.html.twig line 1

  1. {% extends 'knp_menu_base.html.twig' %}
  2. {% macro attributes(attributes) %}
  3. {% for name, value in attributes %}
  4.     {%- if value is not none and value is not same as(false) -%}
  5.         {{- ' %s="%s"'|format(name, value is same as(true) ? name|e : value|e)|raw -}}
  6.     {%- endif -%}
  7. {%- endfor -%}
  8. {% endmacro %}
  9. {% block compressed_root %}
  10. {% apply spaceless %}
  11. {{ block('root') }}
  12. {% endapply %}
  13. {% endblock %}
  14. {% block root %}
  15. {% set listAttributes = item.childrenAttributes %}
  16. {{ block('list') -}}
  17. {% endblock %}
  18. {% block list %}
  19.     {% if item.level == 0 %}
  20.         <ul class="navbar-nav mx-auto mb-2 mb-md-0 gap-md-3">
  21.             {{ block('children') }}
  22.         </ul>
  23.     {% else %}
  24.         {{ block('children') }}
  25.     {% endif %}
  26. {% endblock %}
  27. {% block children %}
  28.     {# save current variables #}
  29.     {% set currentOptions = options %}
  30.     {% set currentItem = item %}
  31.     {# update the depth for children #}
  32.     {% if options.depth is not none %}
  33.     {% set options = options|merge({'depth': currentOptions.depth - 1}) %}
  34.     {% endif %}
  35.     {# update the matchingDepth for children #}
  36.     {% if options.matchingDepth is not none and options.matchingDepth > 0 %}
  37.     {% set options = options|merge({'matchingDepth': currentOptions.matchingDepth - 1}) %}
  38.     {% endif %}
  39.     {% for item in currentItem.children %}
  40.         {{ block('item') }}
  41.     {% endfor %}
  42.     {# restore current variables #}
  43.     {% set item = currentItem %}
  44.     {% set options = currentOptions %}
  45. {% endblock %}
  46. {% block item %}
  47.     {% if item.displayed %}
  48.         <li class="nav-item">
  49.             {{ block('linkElement') }}
  50. {#
  51.             {% if item.hasCHildren %}
  52.                 <div id="menu_items_{{ loop.index }}" class="collapse show">
  53.                     {{ block('list') }}
  54.                 </div>
  55.             {% endif %}
  56. #}
  57.         </li>
  58.     {% endif %}
  59. {% endblock %}
  60. {% block linkElement %}{% import _self as knp_menu %}
  61.     {% set attributes = item.linkAttributes %}
  62.     {% set classes = attributes['class'] is defined ? [attributes['class']] : [] %}
  63.     {% set classes = classes|merge(['nav-link']) %}
  64.     {% if matcher.isCurrent(item) %}
  65.         {% set classes = classes|merge(['active active text-primary']) %}
  66.     {% endif %}
  67.     {% set attributes = attributes|merge({'class': classes|join(' ')}) %}
  68.     <a href="{{ item.uri }}"{{ knp_menu.attributes(attributes) }}>{{ block('label') }}</a>
  69. {% endblock %}
  70. {% block label %}
  71.     {% if item.getExtra('icon') != '' %}
  72.         <i class="me-3 {{ item.getExtra('icon') }}"></i>
  73.     {% endif %}
  74.     {% if options.allow_safe_labels and item.getExtra('safe_label', false) %}
  75.         {{ item.label|raw }}
  76.     {% else %}
  77.         {{ item.label }}
  78.     {% endif %}
  79. {% endblock %}