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

What exactly are page collections?

Started by Muut Archive 10 years ago · 4 replies · 2747 views
10 years ago

...the documentation says

To tell Grav that a specific page should be a listing page and contain child-pages, there are a number of variables that can be used:

And from what I understand, those variables can be put into the header of every page into the yaml part. But what does this cause to happen? I don't understand what I can do with it. Can someone maybe provide a few use cases?

10 years ago

They cause a collection of pages to be collected and made available for a Twig template.

A prime example of this is the blog listing page. You want to display a list of blog posts on a page. So rather than hardcode that list in your Twig for displaying the blog list, you define it in the frontmatter of your page.

This allows you to reuse the blog list page if you need to.

10 years ago

So the page where I define the page collection in the frontmatter is not a blog post itself? Does that mean I have a few blog posts and I create another page which does not contain anything than yaml and the page collection definition?

10 years ago

No, it's not the blog page itself, it's the page that display the list of blog posts, the blog list page.

Best to illustrate with an example.

https://github.com/getgrav/grav-skeleton-blog-site/blob/develop/pages/01.blog/blog.md

and this is an example blog post:

https://github.com/getgrav/grav-skeleton-blog-site/tree/develop/pages/01.blog/sunshine-in-the-hills

This page defines this page (as /blog is the the home alias):

http://www.demo.getgrav.org/blog-skeleton/

10 years ago

Thanks! Now I understand... it really is a handy feature!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1357 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago