You are here

hierarchical-menu.html.twig in Cheeseburger Menu 8

{% macro searchChild(subitems, route_id, page_type, current_url) %}
    {% import _self as macros3 %}
    {% if subitems|length > 0 %}
        <ul style="height: 0; overflow: hidden;">
            {% for item in subitems %}

                {% if (route_id == item.id and page_type == item.type)
                    or (route_id in item.id and page_type == item.type)
                    or (item.id in route_id and page_type == item.type)
                    or (current_url  == item.url)
                %}
                    {% set activeClass = 'active' %}
                {% 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) }}
                </li>

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

{% macro render(menu_tree, route_id, page_type, current_url) %}
    {% import _self as macros2 %}
    {% for item in menu_tree %}

        {% if (route_id == item.id and page_type == item.type)
            or (route_id in item.id and page_type == item.type)
            or (item.id in route_id and page_type == item.type)
            or (current_url  == item.url)
        %}
            {% set activeClass = 'active' %}
        {% 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) }}
            </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) }}
            </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) }}
    </ul>
</div>

File

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