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

In a template, creating a collection for a list of other pages

Started by Muut Archive 10 years ago · 3 replies · 373 views
10 years ago

I am looking at the user guide for theme variables
and also the API for Pages

I am not quite sure how to use this to get the children of a page I am not currently on

For example, I am trying

TWIG
{% set otherpages = pages.children("/someotherpage") %}

but otherpages just gives me the pages at the root of the document. How exactly do I get children for another page.

Given a dir structure like:

TXT
mysite/
  users/
    pages/
     01.home/
         default.md 
     02.someotherpage/
         default.md
         pageA/
           default.md
         pageB/
           default.md

how do i get a listening of the child pages of someotherpage

This is to create a list of certain sub-pages.

10 years ago

Excellent! Exactly what I needed. It seems I went looking everywhere else except the first page. I am not yet sure what works in the API versus templates and how they all work together. I think tracing this function back through will help me better understand.

10 years ago

It takes some digging to figure it all out. The page variable gives you access to the Page object for that page.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1118 9 years ago