vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views/knp_menu.html.twig line 1

Open in your IDE?
  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.hasChildren and options.depth is not same as(0) and item.displayChildren %}
  20.     {% import _self as knp_menu %}
  21.     <ul{{ knp_menu.attributes(listAttributes) }}>
  22.         {{ block('children') }}
  23.     </ul>
  24. {% endif %}
  25. {% endblock %}
  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. {% block item %}
  46. {% if item.displayed %}
  47. {# building the class of the item #}
  48.     {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  49.     {%- if matcher.isCurrent(item) %}
  50.         {%- set classes = classes|merge([options.currentClass]) %}
  51.     {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  52.         {%- set classes = classes|merge([options.ancestorClass]) %}
  53.     {%- endif %}
  54.     {%- if item.actsLikeFirst %}
  55.         {%- set classes = classes|merge([options.firstClass]) %}
  56.     {%- endif %}
  57.     {%- if item.actsLikeLast %}
  58.         {%- set classes = classes|merge([options.lastClass]) %}
  59.     {%- endif %}
  60.     {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
  61.     {% if item.hasChildren and options.depth is not same as(0) %}
  62.         {% if options.branch_class is not empty and item.displayChildren %}
  63.             {%- set classes = classes|merge([options.branch_class]) %}
  64.         {% endif %}
  65.     {% elseif options.leaf_class is not empty %}
  66.         {%- set classes = classes|merge([options.leaf_class]) %}
  67.     {%- endif %}
  68.     {%- set attributes = item.attributes %}
  69.     {%- if classes is not empty %}
  70.         {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  71.     {%- endif %}
  72. {# displaying the item #}
  73.     {% import _self as knp_menu %}
  74.     <li{{ knp_menu.attributes(attributes) }}>
  75.         {%- if item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  76.         {{ block('linkElement') }}
  77.         {%- else %}
  78.         {{ block('spanElement') }}
  79.         {%- endif %}
  80. {# render the list of children#}
  81.         {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  82.         {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
  83.         {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  84.         {{ block('list') }}
  85.     </li>
  86. {% endif %}
  87. {% endblock %}
  88. {% block linkElement %}{% import _self as knp_menu %}<a href="{{ item.uri }}"{{ knp_menu.attributes(item.linkAttributes) }}>{{ block('label') }}</a>{% endblock %}
  89. {% block spanElement %}{% import _self as knp_menu %}<span{{ knp_menu.attributes(item.labelAttributes) }}>{{ block('label') }}</span>{% endblock %}
  90. {% block label %}{% if options.allow_safe_labels and item.getExtra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label }}{% endif %}{% endblock %}