{% macro nav_loop(page, level) %}
  {% import _self as macros %}
  {% for p in page.children.visible %}
    {% set active_page = (p.active or p.activeChild) ? 'active' : '' %}
      {% if level > 0 %}
        <li class="submenu">
          <a href="{{ p.url }}" class="{{ active_page }} submenu">
      {% else %}
        <li>
          <a href="{{ p.url }}" class="{{ active_page }}">
      {% endif %}
          {{ p.menu }}
        </a>

        {% if p.children.visible.count > 0 %}
          <ul class="submenu">
            {{ macros.nav_loop(p, level + 1) }}
          </ul>
        {% endif %}
      </li>
  {% endfor %}
{% endmacro %}
