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

Create collection based on page routes

Solved by pamtbaau View solution

Started by Jamie Pickett 6 years ago · 2 replies · 549 views
6 years ago

I have a folder of content that contains over 500 items. Instead of having the .md file iterate over items: '@self.children' limited to 6 per page, I am looking to see if it is possible to specify 10 pieces of content to feature for the item collection? If I know the slugs of the particular items, can I make a collection from that?

last edited 07/08/20 by Jamie Pickett
6 years ago Solution

@pickettj, If I understand the question correctly, a combination of the following two features of Page Collections might provide you the desired result: A collection of pages specified by their route.

  • @page.self or @page.page - Collection of just the specific page

    This collection takes a slug route of a page as an argument and will return collection containing that page (if it is published and non-modular ):

    YAML
    content:
    items:
    '@page.self': '/blog'
    
  • Complex Collections

    You can also provide multiple complex collection definitions and the resulting collection will be the sum of all the pages found from each of the collection definitions. For example:

    YAML
    content:
    items:
    - '@self.children'
    - '@taxonomy':
    category: [blog, featured]
    

Example of the combination of the two features:
The following page defines a collection containing two items of a blog specified by their route:

YAML
content:
  items:
    - '@page.self': '/blog/hero-classes'
    - '@page.self': '/blog/london-at-night'
6 years ago

@pamtbaau:
@page.self

Thanks for your response. That will do what I am looking for.

Suggested topics

Topic Participants Replies Views Activity
Support · by Paul Hodges, 4 weeks ago
19 485 5 days ago
Support · by Lauw, 7 days ago
2 101 7 days ago
Support · by Anna, 3 weeks ago
4 426 1 week ago
Support · by gtx, 4 weeks ago
4 377 3 weeks ago
Support · by Anna, 1 month ago
9 484 4 weeks ago