Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Retrieve a single page from a page collection

Started by Muut Archive 11 years ago · 3 replies · 474 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 2563 9 years ago
Archive · by Muut Archive, 9 years ago
2 1689 9 years ago
Archive · by Muut Archive, 9 years ago
2 4982 9 years ago
Archive · by Muut Archive, 9 years ago
1 3806 9 years ago
Archive · by Muut Archive, 9 years ago
3 1799 9 years ago