templates/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. {{ block('root') }}
  11. {%- endblock -%}
  12. {%- block root -%}
  13. {% set listAttributes = item.childrenAttributes %}
  14. {{- block('list') -}}
  15. {%- endblock -%}
  16. {%- block list -%}
  17. {%- if item.hasChildren and options.depth is not same as(0) and item.displayChildren -%}
  18. {% import _self as knp_menu %}
  19. {%- if item.level > 0 -%}
  20. <ul {{ knp_menu.attributes(listAttributes) }}>
  21. {%- endif -%}
  22. {{ block('children')|spaceless }}
  23. {%- if item.level > 0 -%}
  24. </ul>
  25. {%- endif -%}
  26. {%- endif -%}
  27. {%- endblock -%}
  28. {%- block children -%}
  29. {# save current variables #}
  30. {% set currentOptions = options %}
  31. {% set currentItem = item %}
  32. {# update the depth for children #}
  33. {% if options.depth is not none %}
  34. {% set options = options|merge({'depth': currentOptions.depth - 1}) %}
  35. {% endif %}
  36. {# update the matchingDepth for children #}
  37. {% if options.matchingDepth is not none and options.matchingDepth > 0 %}
  38. {% set options = options|merge({'matchingDepth': currentOptions.matchingDepth - 1}) %}
  39. {% endif %}
  40. {% for item in currentItem.children %}
  41. {{ block('item') }}
  42. {% endfor %}
  43. {# restore current variables #}
  44. {% set item = currentItem %}
  45. {% set options = currentOptions %}
  46. {%- endblock -%}
  47. {%- block item -%}
  48. {%- if item.displayed -%}
  49. {# building the class of the item #}
  50. {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  51. {%- if matcher.isCurrent(item) %}
  52. {%- set classes = classes|merge([options.currentClass]) %}
  53. {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  54. {%- set classes = classes|merge([options.ancestorClass]) %}
  55. {%- endif %}
  56. {%- if item.actsLikeFirst %}
  57. {%- set classes = classes|merge([options.firstClass]) %}
  58. {%- endif %}
  59. {%- if item.actsLikeLast %}
  60. {%- set classes = classes|merge([options.lastClass]) %}
  61. {%- endif %}
  62. {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
  63. {% if item.hasChildren and currentOptions.depth > 1 %}
  64. {%- set classes = classes|merge(['has-child']) %}
  65. {% if options.branch_class is not empty and item.displayChildren %}
  66. {%- set classes = classes|merge([options.branch_class]) %}
  67. {% endif %}
  68. {% elseif options.leaf_class is not empty %}
  69. {%- set classes = classes|merge([options.leaf_class]) %}
  70. {%- endif %}
  71. {%- set attributes = item.attributes %}
  72. {%- if classes is not empty %}
  73. {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  74. {%- endif %}
  75. {# displaying the item #}
  76. {% import _self as knp_menu %}
  77. <li{{ knp_menu.attributes(attributes) }}>
  78. {%- if item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  79. {{ block('linkElement') }}
  80. {%- else %}
  81. {{ block('spanElement') }}
  82. {%- endif %}
  83. {# render the list of children#}
  84. {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  85. {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
  86. {%- set childrenClasses = childrenClasses|merge([item.children|length > 6 ? 'columns-' ~( (item.children|length / 6)|round(0, 'ceil') ) : 'nocolumns']) %}
  87. {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  88. {{ block('list') }}
  89. </li>
  90. {%- endif -%}
  91. {%- endblock -%}
  92. {% block linkElement %}{% import _self as knp_menu %}
  93. <a href="{{ item.uri }}"{{ knp_menu.attributes(item.linkAttributes) }}>{{ block('label') }}
  94. {% if item.hasChildren and currentOptions.depth > 1 %}
  95. <svg aria-label="Ikona menu">
  96. <use xlink:href="#chevron-down-icon"></use>
  97. </svg>
  98. {% endif %}
  99. </a>
  100. {% endblock %}
  101. {% block spanElement %}{% import _self as knp_menu %}<span{{ knp_menu.attributes(item.labelAttributes) }}>{{ block('label') }} {% if item.hasChildren and currentOptions.depth > 1 %}<i class="icon-down"></i>{% endif %}</span>{% endblock %}
  102. {% block label %}{% if options.allow_safe_labels and item.getExtra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label }}{% endif %}{% if item.hasChildren %} {% endif %}{% endblock %}