templates/layout/nav/main.html.twig line 1

Open in your IDE?
  1. {% if not document is defined or not document %}
  2.     {% set document = pimcore_document(1) %}
  3. {% endif %}
  4. {% set navStartNode = document.getProperty('mainNavStartNode') %}
  5. {% if not 
  6.     (navStartNode is instanceof('\\Pimcore\\Model\\Document\\Page') 
  7.     or navStartNode is instanceof('\\Pimcore\\Model\\Document\\Folder')
  8.     or navStartNode is instanceof('\\Pimcore\\Model\\Document\\Link')
  9. ) %}
  10.     {% set navStartNode = pimcore_document(1) %}
  11. {% endif %}
  12. {% set mainNavigation = pimcore_build_nav({
  13.     active: document,
  14.     root: navStartNode
  15. }) %}
  16. {% set menuRenderer = pimcore_nav_renderer('menu') %}
  17. {% for page in mainNavigation %}
  18.     {% if page.isVisible() and menuRenderer.accept(page)  %}
  19.         {# children #}
  20.         {# {% set hasChildren = page.pages %} #}
  21.         
  22.         {% set hasChildren = false %}
  23.         {% for child in page.pages %}
  24.             {% if child._visible %}
  25.                 {% set hasChildren = true %}
  26.             {% endif %}
  27.         {% endfor %}
  28.         {# active #}
  29.         {% if page.href == app.request.pathInfo %}
  30.             {% set activeClass = 'active' %}
  31.         {% else %}
  32.             {% set activeClass = '' %}
  33.         {% endif %}
  34.         {# active child #}
  35.         {% if hasChildren %}
  36.             {% for child in page.pages %}
  37.                 {% if child._active %}
  38.                     {% set activeClass = 'active' %}
  39.                 {% endif %}
  40.             {% endfor %}
  41.         {% endif %}
  42.         {% if not hasChildren %}
  43.             <li class="{{ activeClass }}">
  44.                 <a href="{{ page.getHref() }}">{{ page.getLabel() }}</a>
  45.             </li>
  46.         {% else %}
  47.             <li class="has-dropdown {{ activeClass }}" data-dropdown="dropdown-{{ page.id }}">
  48.                 <a href="{{ page.getHref() }}">{{ page.getLabel() }}</a>
  49.                 <ul class="dropdown" id="dropdown-{{ page.id }}">
  50.                     {% for child in page.pages %}
  51.                         {% if child.isVisible() and menuRenderer.accept(child) %}
  52.                             
  53.                             {# active #}
  54.                             {% if child._active %}
  55.                                 {% set activeChildClass = 'active' %}
  56.                             {% else %}
  57.                                 {% set activeChildClass = '' %}
  58.                             {% endif %}
  59.                             <li class="dropdown-link {{ activeChildClass }}">
  60.                                 <a href="{{ child.getHref() }}">{{ child.getLabel() }}</a>
  61.                             </li>
  62.                         {% endif %}
  63.                     {% endfor %}
  64.                 </ul>
  65.             </li>
  66.         {% endif %}
  67.     {% endif %}
  68. {% endfor %}