Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Accessing Collections in Twig

Solved by hughbris View solution

Started by rohan sharma 8 years ago · 3 replies · 2036 views
8 years ago

Hi,
I did not understand the page collection that can be accessed in twig template in this link - https://learn.getgrav.org/content/collections.

I am learning with antimatter theme. I created a listing page using blog.md and made the collection in the blog.md frontmatter. But, in the section accessing collections in twig it says : Grav creates a collection page.collection that you can access in a twig template with:

{% for p in page.collection %}
\<h2>{{ p.title }}\</h2>
{{ p.summary }}\
{% endfor %}

In which file is this code contained in? in the blog.html.twig ?

8 years ago Solution

This is only an example of how you would access the collection in Twig.

The part of antimatter that is similar is contained in blog.html.twig, line 22.

Let me know if that clears it up for you.

8 years ago

Thanks for replying. I got it. I guess I will have to look up the documentation of twig so that I can stop asking these silly questions.

8 years ago

Not stupid, it's easy to misread the docs when you have pre-existing ideas :)

Suggested topics

Topic Participants Replies Views Activity
General · by themetman, 23 hours ago
2 40 17 hours ago
General · by Hanns Mattes, 1 week ago
0 121 1 week ago
General · by Karmalakas, 1 week ago
2 185 1 week ago
General · by Hanns Mattes, 3 weeks ago
0 235 3 weeks ago
General · by Dima, 4 weeks ago
1 211 4 weeks ago