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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Accessing Collections in Twig

Solved by Hugh Barnes View solution

Started by rohan sharma 8 years ago · 3 replies · 1718 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 Jerry Hunt, 4 days ago
2 85 13 hours ago
General · by pamtbaau, 18 hours ago
1 60 18 hours ago
General · by Andy Miller, 1 day ago
0 47 1 day ago
General · by Marcel, 12 months ago
6 350 5 days ago
General · by Duc , 6 days ago
3 44 5 days ago