---
title: 'Collect all lowest level descendants'
url: 'https://getgrav.org/forum/themes-styling/collect-all-lowest-level-descendants-t827'
markdown: 'https://getgrav.org/forum/themes-styling/collect-all-lowest-level-descendants-t827.md'
date: '2026-06-21'
description: 'I have a page that has children, and those children have children (see example structure below). I want to display all the level 3 pages together in one place.'
---

[Themes & Styling](https://getgrav.org/forum/themes-styling)

#   Collect all lowest level descendants 

 Solved by - [View solution](https://getgrav.org/forum/themes-styling/collect-all-lowest-level-descendants-t827#post-20119)

  Started by Diego Vogel 9 years ago · 3 replies · 1298 views    

 [9 years ago](https://getgrav.org/forum/themes-styling/collect-all-lowest-level-descendants-t827#post-19693 "Permalink") 

I have a page that has children, and those children have children (see example structure below). I want to display all the level 3 pages together in one place.

```
 level 1 page
    level 2 page
        level 3 page
        level 3 page
    level 2 page
        level 3 page
        level 3 page
```

I tried using taxonomy to do this, by giving all the level 3 pages a common tag or category and creating a collection of that tag/category, but the collection included the level 2 pages, as if they were taking on their child page taxonomy.

Now I'm trying to use a for loop to go through each level 2 page one by one and output all child pages. As shown below.

```twig
{% set options = { items: {'@page.children': '/level1page'} } %}
{% set lvl2_collection = page.collection(options) %}

{% for lvl2page in lvl2_collection %}

    {% set options = { items: {'@page.children': '/level1page/{{ lvl2page.title|lower }}'}, 'order': {'by': 'date', 'dir': 'desc'} } %}
    {% set lvl3_collection = page.collection(options) %}

        <div>
            {% for lvl3 in lvl3_collection %}
                <div>
                    {% lvl3.content %}
                </div>
            {% endfor %}
        </div>

{% endfor %}
```

For some reason this returns an empty collection (no content). I think the problem is where I include {{ lvl2page.title|lower }} in the options for the second collection. If I replace that with the title of the first level 2 page (typed out) it creates a collection no problem, but I need this to change for each cycle of the first for loop so it goes through all the level 2 pages.

Is there a way to do this, or a totally different method for collecting all the level 3 pages? Any help is much appreciated!

 [9 years ago](https://getgrav.org/forum/themes-styling/collect-all-lowest-level-descendants-t827#post-20119 "Permalink")  Solution 

Hi jego,

try this, it should work:

```twig
{% for p in page.collection %}
{% if loop.index > 2  %}
    ...
{% endif %}
{% endfor %}
```

with the loop.index > "Number" you actually set the index you want show(your level) - it shows also all deeper levels so in case, that your structure get more "levels" you should adjust ist or combine it with another condition

 [9 years ago](https://getgrav.org/forum/themes-styling/collect-all-lowest-level-descendants-t827#post-20123 "Permalink") 

Maybe you should do that with a plugin which uses PHP to build a collection where all pages with no children are collected.

See: <https://learn.getgrav.org/cookbook/plugin-recipes#iterating-through-pages-and-media> and <https://learn.getgrav.org/content/collections#php-collections>

 [9 years ago](https://getgrav.org/forum/themes-styling/collect-all-lowest-level-descendants-t827#post-20125 "Permalink") 

Thanks for the help guys. After posting the question I ended up restructuring the page hierarchy to fix the issue.

ehllo - I went ahead and marked your reply as an answer because I'm pretty sure what you're saying would've worked for this situation.

[Log in](https://getgrav.org/login?return=%2Fforum%2Fthemes-styling%2Fcollect-all-lowest-level-descendants-t827) to reply.

###  Suggested topics

 | Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| [Modular Page Background Image Display](https://getgrav.org/forum/themes-styling/modular-page-background-image-display-t9486)    [Themes & Styling](https://getgrav.org/forum/themes-styling) · by TomW, 2 weeks ago |  | 2 | 200 | [2 days ago](https://getgrav.org/forum/themes-styling/modular-page-background-image-display-t9486 "by TomW") |
| [Inheriting a Theme does not quite work correctly](https://getgrav.org/forum/themes-styling/inheriting-a-theme-does-not-quite-work-correctly-t9501)    [Themes & Styling](https://getgrav.org/forum/themes-styling) · by themetman, 3 days ago |  | 0 | 48 | [3 days ago](https://getgrav.org/forum/themes-styling/inheriting-a-theme-does-not-quite-work-correctly-t9501 "by themetman") |
| [\[quark\] mobile menu as the modular page menu](https://getgrav.org/forum/themes-styling/quark-mobile-menu-as-the-modular-page-menu-t1132)    [Themes & Styling](https://getgrav.org/forum/themes-styling) · by Bruno, 4 years ago |  | 4 | 1321 | [3 days ago](https://getgrav.org/forum/themes-styling/quark-mobile-menu-as-the-modular-page-menu-t1132 "by AH") |
| [Grav2 with Quark2 – All pages in the hamburger-menu of a one-pager](https://getgrav.org/forum/themes-styling/grav2-with-quark2-all-pages-in-the-hamburger-menu-of-a-one-pager-t9485)    [Themes & Styling](https://getgrav.org/forum/themes-styling) · by AH, 2 weeks ago |  | 0 | 173 | [2 weeks ago](https://getgrav.org/forum/themes-styling/grav2-with-quark2-all-pages-in-the-hamburger-menu-of-a-one-pager-t9485 "by AH") |
| [Is it a way to get the "content - summary" in a twig template ?](https://getgrav.org/forum/themes-styling/is-it-a-way-to-get-the-content-summary-in-a-twig-template-t9431)    [Themes & Styling](https://getgrav.org/forum/themes-styling) · by FrViPofm, 2 months ago |  | 4 | 668 | [1 month ago](https://getgrav.org/forum/themes-styling/is-it-a-way-to-get-the-content-summary-in-a-twig-template-t9431 "by Paul Hibbitts") |
