menu_tree_macro.html.twig 2.28 KB
Newer Older
Julien Jorry committed
1 2 3 4 5
{% macro menu(items, currentPath) %}
    {% import _self as self %}

    {% for menuItem in items %}
        {% set url = menuItem.url %}
Julien Jorry committed
6
        {% set attributes = "menuitem" %}
Julien Jorry committed
7 8 9 10 11 12 13 14 15 16 17 18 19
        {% if menuItem.classAttribute %}
            {% set attributes = attributes ~ ' ' ~ menuItem.classAttribute %}
        {% endif %}
        {% if menuItem.hasChild() %}
            {% set attributes = attributes ~ ' has-child dropdown' %}
            {% for childItem in menuItem.children %}
                {% set childUrl = childItem.url %}
                {% if childUrl == currentPath %}
                    {% set attributes = attributes ~ ' active current-parent' %}
                {% endif %}
            {% endfor %}
        {% endif %}

Julien Jorry committed
20
        <li class="nav-item {% if menuItem.hasChild() %}dropdown{% endif %}{{ attributes }}" role="menuitem">
Julien Jorry committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
            {% if menuItem.hasChild() %}
                <a href="#" id="navbarDropdown{{ menuItem.id }}" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link parent dropdown-toggle {% if currentPath == url %}current{% endif %}" {% if menuItem.target %} target="_blank"{% endif %}>{{ menuItem.name }}</a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown{{ menuItem.id }}">
                {{ self.menuchild(menuItem.children, currentPath) }}
                </div>
            {% else %}
                <a href="{{ url }}" class="nav-link {% if currentPath == url %}current{% endif %}" {% if menuItem.target %} target="_blank"{% endif %}>{{ menuItem.name }}</a>
            {% endif %}
        </li>
    {% endfor %}
{% endmacro %}
{% macro menuchild(items, currentPath) %}
    {% import _self as self %}
    {% for menuItem in items %}
        {% set url = menuItem.url %}
36 37 38 39 40 41 42 43
        {% if tav_env == 1 and menuItem.name == "Carte des prestataires" %}
            {% set name = "Carte des points de vente" %}
        {% elseif tav_env == 1 and menuItem.name == "Liste des prestataires" %}
            {% set name = "Liste des points de vente" %}
        {% else %}
            {% set name = menuItem.name %}
        {% endif %}
        <a href="{{ url }}" class="dropdown-item {% if currentPath == url %}current{% endif %}" {% if menuItem.target %} target="_blank"{% endif %}>{{ name }}</a>
Julien Jorry committed
44 45
    {% endfor %}
{% endmacro %}