You are here

hierarchical-taxonomy-menu.html.twig in Hierarchical Taxonomy Menu 8

{% macro menu_links(menu_tree, route_tid, current_depth, max_depth, collapsible) %}
  {% import _self as macros %}
  {% for item in menu_tree %}
    {%
      set liClass = [
        item.subitem and current_depth < max_depth ? 'menu-item menu-item--expanded block-taxonomymenu__menu-item block-taxonomymenu__menu-item--expanded' : 'menu-item block-taxonomymenu__menu-item',
        route_tid == item.tid ? 'menu-item--active block-taxonomymenu__menu-item--active' : ''
      ]
    %}
    <li class="{{ liClass|join(' ') }}">
      {% if item.image %}
        <img class="menu-item-image block-taxonomymenu__image" src="{{ item.image }}" alt="{{ item.name }}" {% if item.use_image_style == false %}height="{{ item.height }}" width="{{ item.width }}"{% endif %} />
      {% endif %}
        <a href="{{ item.url }}" class="block-taxonomymenu__link {% if route_tid == item.tid %}active block-taxonomymenu__link--active{% endif %}">{{ item.name }}{% if item.show_count == true %} [{{ item.entities|length }}]{% endif %}</a>
      {% if item.subitem and current_depth < max_depth %}
        {% if item.interactive_parent %}
          <i class="arrow-right parent-toggle" aria-hidden="true"></i><span class="visually-hidden">Expand Secondary Navigation Menu</span>
        {% endif %}
        {% if collapsible == TRUE %}
          <ul class="menu block-taxonomymenu__submenu collapsed-submenu">
        {% else %}
          <ul class="menu block-taxonomymenu__submenu">
        {% endif %}
          {{ macros.menu_links(item.subitem, route_tid, current_depth + 1, max_depth, collapsible) }}
        </ul>
      {% endif %}
    </li>
  {% endfor %}
{% endmacro %}

{% import _self as macros %}
<ul class="menu hierarchical-taxonomy-menu block-taxonomymenu__menu">
  {{ macros.menu_links(menu_tree, route_tid, 0, max_depth, collapsible) }}
</ul>

File

templates/hierarchical-taxonomy-menu.html.twig
View source
  1. {% macro menu_links(menu_tree, route_tid, current_depth, max_depth, collapsible) %}
  2. {% import _self as macros %}
  3. {% for item in menu_tree %}
  4. {%
  5. set liClass = [
  6. item.subitem and current_depth < max_depth ? 'menu-item menu-item--expanded block-taxonomymenu__menu-item block-taxonomymenu__menu-item--expanded' : 'menu-item block-taxonomymenu__menu-item',
  7. route_tid == item.tid ? 'menu-item--active block-taxonomymenu__menu-item--active' : ''
  8. ]
  9. %}
  10. <li class="{{ liClass|join(' ') }}">
  11. {% if item.image %}
  12. <img class="menu-item-image block-taxonomymenu__image" src="{{ item.image }}" alt="{{ item.name }}" {% if item.use_image_style == false %}height="{{ item.height }}" width="{{ item.width }}"{% endif %} />
  13. {% endif %}
  14. <a href="{{ item.url }}" class="block-taxonomymenu__link {% if route_tid == item.tid %}active block-taxonomymenu__link--active{% endif %}">{{ item.name }}{% if item.show_count == true %} [{{ item.entities|length }}]{% endif %}</a>
  15. {% if item.subitem and current_depth < max_depth %}
  16. {% if item.interactive_parent %}
  17. <i class="arrow-right parent-toggle" aria-hidden="true"></i><span class="visually-hidden">Expand Secondary Navigation Menu</span>
  18. {% endif %}
  19. {% if collapsible == TRUE %}
  20. <ul class="menu block-taxonomymenu__submenu collapsed-submenu">
  21. {% else %}
  22. <ul class="menu block-taxonomymenu__submenu">
  23. {% endif %}
  24. {{ macros.menu_links(item.subitem, route_tid, current_depth + 1, max_depth, collapsible) }}
  25. </ul>
  26. {% endif %}
  27. </li>
  28. {% endfor %}
  29. {% endmacro %}
  30. {% import _self as macros %}
  31. <ul class="menu hierarchical-taxonomy-menu block-taxonomymenu__menu">
  32. {{ macros.menu_links(menu_tree, route_tid, 0, max_depth, collapsible) }}
  33. </ul>