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. {{- 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. <ul vocab="https://schema.org/" typeof="BreadcrumbList"{{ knp_menu.attributes(listAttributes) }}>
  20. {{ block('children') }}
  21. </ul>
  22. {% endif %}
  23. {% endblock %}
  24. {% block children %}
  25. {# save current variables #}
  26. {% set currentOptions = options %}
  27. {% set currentItem = item %}
  28. {# update the depth for children #}
  29. {% if options.depth is not none %}
  30. {% set options = options|merge({'depth': currentOptions.depth - 1}) %}
  31. {% endif %}
  32. {# update the matchingDepth for children #}
  33. {% if options.matchingDepth is not none and options.matchingDepth > 0 %}
  34. {% set options = options|merge({'matchingDepth': currentOptions.matchingDepth - 1}) %}
  35. {% endif %}
  36. {% for item in currentItem.children %}
  37. {{ block('item') }}
  38. {% endfor %}
  39. {# restore current variables #}
  40. {% set item = currentItem %}
  41. {% set options = currentOptions %}
  42. {% endblock %}
  43. {% block item %}
  44. {% if item.displayed %}
  45. {# building the class of the item #}
  46. {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  47. {%- if matcher.isCurrent(item) %}
  48. {%- set classes = classes|merge([options.currentClass]) %}
  49. {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  50. {%- set classes = classes|merge([options.ancestorClass]) %}
  51. {%- endif %}
  52. {%- if item.actsLikeFirst %}
  53. {%- set classes = classes|merge([options.firstClass]) %}
  54. {%- endif %}
  55. {%- if item.actsLikeLast %}
  56. {%- set classes = classes|merge([options.lastClass]) %}
  57. {%- endif %}
  58. {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
  59. {% if item.hasChildren and options.depth is not same as(0) %}
  60. {% if options.branch_class is not empty and item.displayChildren %}
  61. {%- set classes = classes|merge([options.branch_class]) %}
  62. {% endif %}
  63. {% elseif options.leaf_class is not empty %}
  64. {%- set classes = classes|merge([options.leaf_class]) %}
  65. {%- endif %}
  66. {%- set attributes = item.attributes %}
  67. {%- if classes is not empty %}
  68. {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  69. {%- endif %}
  70. {# displaying the item #}
  71. {% import _self as knp_menu %}
  72. {% set markupCondition = item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  73. <li {%- if markupCondition %} property="itemListElement" typeof="ListItem" {% else %} class="no-link" {% endif %} {{ knp_menu.attributes(attributes) }} >
  74. {%- if markupCondition %}
  75. {{ block('linkElement') }}
  76. {%- else %}
  77. {{ block('spanElement') }}
  78. {%- endif %}
  79. {# render the list of children#}
  80. {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  81. {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
  82. {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  83. {{ block('list') }}
  84. {%- if markupCondition %}
  85. <meta property="position" content="{{ loop.index }}" />
  86. {% endif %}
  87. </li>
  88. {% endif %}
  89. {% endblock %}
  90. {% 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 %}
  91. {% block spanElement %}{% import _self as knp_menu %}<span class="link" {{ knp_menu.attributes(item.labelAttributes) }}>{{ block('label') }}</span>{% endblock %}
  92. {% block label %}
  93. {% if item.attributes and options.mobileView is defined and options.mobileView %}
  94. {{ item.attributes.title }}
  95. {% else %}
  96. {% if options.allow_safe_labels and item.getExtra('safe_label', false) %}
  97. {{ item.label|raw }}
  98. {% else %}
  99. {{ item.label }}
  100. {% endif %}
  101. {% endif %}
  102. {% endblock %}