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

Retrieve a single page from a page collection

Started by Muut Archive 11 years ago · 3 replies · 371 views
11 years ago

how can I retrieve a single page from a page collection in one line?

TWIG
{% set second_page = page.children[1] %}

something like this?

11 years ago

Yes you can do that, it will do that if your array is integer based. However, i don't 'think' collections are. One way to get around this is to use []notation but with the slice syntactic sugar:

TWIG
{% set second_page = page.children[2:2] %}

http://twig.sensiolabs.org/doc/filters/slice.html

11 years ago

Try dumping page.children and make sure you actually have children available:

TWIG
{{ dump(page.children) }}

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