{% macro menu(items, currentPath) %}
    {% import _self as self %}

    {% for menuItem in items %}
        {% set url = menuItem.url %}
        {% set attributes = "menuitem" %}
        {% 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 %}

        <li class="nav-item {% if menuItem.hasChild() %}dropdown{% endif %}{{ attributes }}" role="menuitem">
            {% 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 %}

        {# In tav env, only display some entries with a different name #}
        {% if tav_env == 1 %}
            {% set name = null %}
            {% if menuItem.name == "Carte des prestataires" %}
                {% set name = "Carte des points de vente" %}
            {% elseif menuItem.name == "Rubriques" %}
                {% set name = "Les différents points de vente" %}
            {% endif %}

            {% if name != null %}
                <a href="{{ url }}" class="dropdown-item {% if currentPath == url %}current{% endif %}" {% if menuItem.target %} target="_blank"{% endif %}>{{ name }}</a>
            {% endif %}
        {% else %}
            <a href="{{ url }}" class="dropdown-item {% if currentPath == url %}current{% endif %}" {% if menuItem.target %} target="_blank"{% endif %}>{{ menuItem.name }}</a>
        {% endif %}
    {% endfor %}
{% endmacro %}