You are here

hierarchical-menu.html.twig in Cheeseburger Menu 8.2

{% macro searchChild(subitems, route_id, page_type, current_url, active) %}
    {% import _self as macros3 %}
    {% if subitems|length > 0 %}
        <ul style="height: 0; overflow: hidden;">
            {% for item in subitems %}
                {% if active is not empty %}
                    {% if (item.id == active.id)  and (item.url == active.url) and (item.type == active.type) %}
                        {% set activeClass = 'active' %}
                    {% else %}
                        {% set activeClass = '' %}
                    {% endif %}
                {% else %}
                    {% set activeClass = '' %}
                {% endif %}
                {% if item.subitem|length > 0 %}
                <li class="cheeseburger-menu__menu-list-item cheeseburger-menu__menu-list-item--child cheeseburger-menu__menu-list-item--expanded {{ activeClass }}">
                {% else %}
                    <li class="cheeseburger-menu__menu-list-item cheeseburger-menu__menu-list-item--child {{ activeClass }}">
                {% endif %}

                {% if item.icon %}
                    <img src="{{ item.icon }}" class="cheeseburger-menu__menu-list-item-image">
                {% endif %}
                <a href="{{ item.url }}"
                   class="cheeseburger-menu__menu-list-item-link {{ activeClass }}">{{ item.name }}</a>
                {{ macros3.searchChild(item.subitem, route_id, page_type, current_url, active) }}
                </li>

            {% endfor %}
        </ul>
    {% endif %}
{% endmacro %}

{% macro render(menu_tree, route_id, page_type, current_url, active) %}
    {% import _self as macros2 %}
    {% for item in menu_tree %}
        {% if active is not empty %}
            {% if (item.id == active.id)  and (item.url == active.url) and (item.type == active.type) %}
                {% set activeClass = 'active' %}
            {% else %}
                {% set activeClass = '' %}
            {% endif %}
        {% else %}
            {% set activeClass = '' %}
        {% endif %}
        {% if item.subitem|length > 0 %}
            <li class="cheeseburger-menu__menu-list-item cheeseburger-menu__menu-list-item--parent cheeseburger-menu__menu-list-item--expanded {{ activeClass }}">
                {% if item.icon %}
                    <img src="{{ item.icon }}" class="menu-item-image">
                {% endif %}
                <span class="cheeseburger-menu__menu-list-item-link cheeseburger-menu__menu-list-item-link--span {{ activeClass }}">{{ item.name }}</span>
                {{ macros2.searchChild(item.subitem, route_id, page_type, current_url, active) }}
            </li>
        {% else %}
            <li class="cheeseburger-menu__menu-list-item {{ activeClass }}">
                {% if item.icon %}
                    <img src="{{ item.icon }}" class="menu-item-image">
                {% endif %}
                <a href="{{ item.url }}"
                   class="cheeseburger-menu__menu-list-item-link {{ activeClass }}">{{ item.name }}</a>
                {{ macros2.searchChild(item.subitem, route_id, page_type, current_url, active) }}
            </li>
        {% endif %}



    {% endfor %}
{% endmacro %}

{% import _self as macros %}
<div class="cheeseburger-menu__menu cheeseburger-menu__menu--{{ machine_name }}"
     data-drupal-selector="cheeseburger-menu--{{ machine_name }}">
    <span class="cheeseburger-menu__menu-list-trigger"></span>
    {% if title != FALSE %}
        <div class="cheeseburger-menu__menu-title">{{ title }}</div>
    {% endif %}
    <ul class="cheeseburger-menu__menu-list">
        {{ macros.render(menu_tree, route_id, page_type, current_url, active) }}
    </ul>
</div>

File

templates/hierarchical-menu.html.twig
View source
  1. {% macro searchChild(subitems, route_id, page_type, current_url, active) %}
  2. {% import _self as macros3 %}
  3. {% if subitems|length > 0 %}
  4. <ul style="height: 0; overflow: hidden;">
  5. {% for item in subitems %}
  6. {% if active is not empty %}
  7. {% if (item.id == active.id) and (item.url == active.url) and (item.type == active.type) %}
  8. {% set activeClass = 'active' %}
  9. {% else %}
  10. {% set activeClass = '' %}
  11. {% endif %}
  12. {% else %}
  13. {% set activeClass = '' %}
  14. {% endif %}
  15. {% if item.subitem|length > 0 %}
  16. <li class="cheeseburger-menu__menu-list-item cheeseburger-menu__menu-list-item--child cheeseburger-menu__menu-list-item--expanded {{ activeClass }}">
  17. {% else %}
  18. <li class="cheeseburger-menu__menu-list-item cheeseburger-menu__menu-list-item--child {{ activeClass }}">
  19. {% endif %}
  20. {% if item.icon %}
  21. <img src="{{ item.icon }}" class="cheeseburger-menu__menu-list-item-image">
  22. {% endif %}
  23. <a href="{{ item.url }}"
  24. class="cheeseburger-menu__menu-list-item-link {{ activeClass }}">{{ item.name }}</a>
  25. {{ macros3.searchChild(item.subitem, route_id, page_type, current_url, active) }}
  26. </li>
  27. {% endfor %}
  28. </ul>
  29. {% endif %}
  30. {% endmacro %}
  31. {% macro render(menu_tree, route_id, page_type, current_url, active) %}
  32. {% import _self as macros2 %}
  33. {% for item in menu_tree %}
  34. {% if active is not empty %}
  35. {% if (item.id == active.id) and (item.url == active.url) and (item.type == active.type) %}
  36. {% set activeClass = 'active' %}
  37. {% else %}
  38. {% set activeClass = '' %}
  39. {% endif %}
  40. {% else %}
  41. {% set activeClass = '' %}
  42. {% endif %}
  43. {% if item.subitem|length > 0 %}
  44. <li class="cheeseburger-menu__menu-list-item cheeseburger-menu__menu-list-item--parent cheeseburger-menu__menu-list-item--expanded {{ activeClass }}">
  45. {% if item.icon %}
  46. <img src="{{ item.icon }}" class="menu-item-image">
  47. {% endif %}
  48. <span class="cheeseburger-menu__menu-list-item-link cheeseburger-menu__menu-list-item-link--span {{ activeClass }}">{{ item.name }}</span>
  49. {{ macros2.searchChild(item.subitem, route_id, page_type, current_url, active) }}
  50. </li>
  51. {% else %}
  52. <li class="cheeseburger-menu__menu-list-item {{ activeClass }}">
  53. {% if item.icon %}
  54. <img src="{{ item.icon }}" class="menu-item-image">
  55. {% endif %}
  56. <a href="{{ item.url }}"
  57. class="cheeseburger-menu__menu-list-item-link {{ activeClass }}">{{ item.name }}</a>
  58. {{ macros2.searchChild(item.subitem, route_id, page_type, current_url, active) }}
  59. </li>
  60. {% endif %}
  61. {% endfor %}
  62. {% endmacro %}
  63. {% import _self as macros %}
  64. <div class="cheeseburger-menu__menu cheeseburger-menu__menu--{{ machine_name }}"
  65. data-drupal-selector="cheeseburger-menu--{{ machine_name }}">
  66. <span class="cheeseburger-menu__menu-list-trigger"></span>
  67. {% if title != FALSE %}
  68. <div class="cheeseburger-menu__menu-title">{{ title }}</div>
  69. {% endif %}
  70. <ul class="cheeseburger-menu__menu-list">
  71. {{ macros.render(menu_tree, route_id, page_type, current_url, active) }}
  72. </ul>
  73. </div>