Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

"Grandchildren" 3rd level menu items not working

Started by Muut Archive 10 years ago · 1 replies · 503 views
10 years ago

Hi everyone. I'm trying to create a 3 level deep menu. The second level works but the "grandchildren" don't. Can someone advise me on where I can find the answers to this problem.
Thanks!

TWIG

<ul class="menu">
        {% for page in pages.children.visible %}
            {% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
            <li class="{{ current_page }}">
                <a href="{{ page.url }}">{{ page.menu }}</a>
                {% if page.children %}
                  <ul class="">
                  {% for child in page.children %}
                      {% if child.visible %}
                        {% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
                          <li class="{{ current_page }}">
                            <a href="{{ child.url }}">{{ child.menu }}</a>
                            {% set grandchild = child.getChildren %}

                              <ul class="">
                                {% for grandchild in child.get_children %}
                                      <li class= "{{ current_page }}">
                                        <a href="{{ grandchild.url }}">{{ grandchild.menu }}</a>
                                      </li>
                              {% endfor %}
                              </ul>

                          </li>
                      {% endif %}
                  {% endfor %}
                  </ul>
                {% endif %}
            </li>
        {% endfor %}
</ul>
---
10 years ago

solved: for anyone needing a 3 level menu, here you go:

TWIG

<ul class="menu">
  {% for page in pages.children.visible %}
  {% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
  <li class="{{ current_page }}">
      <a href="{{ page.url }}">{{ page.menu }}</a>
      {% if page.children %}
        <ul class="">
        {% for child in page.children %}
            {% if child.visible %}
              {% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
                <li class="{{ current_page }}">
                  <a href="{{ child.url }}">{{ child.menu }}</a>

                    <ul class="">
                      {% for grandchild in child.children %}
                            <li class="{{ current_page }}">
                              <a href="{{ grandchild.url }}">{{ grandchild.menu }}</a>
                            </li>
                    {% endfor %} 
                    </ul>

                </li>
            {% endif %}
        {% endfor %}
        </ul>
      {% endif %}
  </li>
  {% endfor %}
</ul>
---

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1357 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago