Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Accessing Collections in Twig

Solved by hughbris View solution

Started by rohan sharma 8 years ago · 3 replies · 1875 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 jeremycherfas, 1 week ago
4 181 2 days ago
General · by lynbor, 6 days ago
2 124 3 days ago
General · by Old Man Umby, 1 week ago
1 100 1 week ago
General · by Sebastian, 2 weeks ago
1 124 1 week ago
General · by Andy Miller, 3 weeks ago
0 248 3 weeks ago