templates/knp_breadcrumbs.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.hasChildren and options.depth is not same as(0) and item.displayChildren %}
  20. {% import _self as knp_menu %}
  21. <ul vocab="https://schema.org/" typeof="BreadcrumbList"{{ 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. {% set markupCondition = item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  75. <li {%- if markupCondition %} property="itemListElement" typeof="ListItem" {% else %} class="no-link" {% endif %} {{ knp_menu.attributes(attributes) }} >
  76. {%- if markupCondition %}
  77. {{ block('linkElement') }}
  78. {%- else %}
  79. {{ block('spanElement') }}
  80. {%- endif %}
  81. {# render the list of children#}
  82. {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  83. {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
  84. {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  85. {{ block('list') }}
  86. {%- if markupCondition %}
  87. <meta property="position" content="{{ loop.index }}" />
  88. {% endif %}
  89. </li>
  90. {% endif %}
  91. {% endblock %}
  92. {% block linkElement %}{% import _self as knp_menu %}<a class="link" href="{{ item.uri }}" property="item" typeof="WebPage"{{ knp_menu.attributes(item.linkAttributes) }}><span property="name">{{ block('label') }}</span></a>{% endblock %}
  93. {% block spanElement %}{% import _self as knp_menu %}<span class="link" {{ knp_menu.attributes(item.labelAttributes) }}>{{ block('label') }}</span>{% endblock %}
  94. {% block label %}
  95. {% if item.attributes and options.mobileView is defined and options.mobileView %}
  96. {{ item.attributes.title }}
  97. {% else %}
  98. {% if options.allow_safe_labels and item.getExtra('safe_label', false) %}
  99. {{ item.label|raw }}
  100. {% else %}
  101. {{ item.label }}
  102. {% endif %}
  103. {% endif %}
  104. {% endblock %}