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.

Content & Markdown

Filtering collection by category

Solved by Vadym View solution

Started by John Martyn 3 years ago · 2 replies · 468 views
3 years ago

Hi!

I'm having some trouble filtering a collection of pages by category. This seems very simple and close to issues solved previously on the forum, but I can't seem to be able to solve this.

I'm building a website for a small film fest. I have a page 'movies' that ideally would display children of page 'programme', filtered to display only pages of category 'movie'. (The 'programme' page collection also has concerts and other events).

I guess this would start this way:

YAML
title: Films
content:
    items: 
    - '@page.children': '/programme'
    filter:

But what should I have in 'filter'?

I'm afraid I spent the afternoon on this. Any help is much appreciated!

3 years ago Solution

If I understand correctly what you want to achieve, try this

YAML
title: Films
content:
    items:
      '@page.children': '/programme'
movie:
    items:
       '@taxonomy.category': movie

and add to the page template

TWIG
{# collection #}
{% set collection = page.collection %}
{% set movie_collection = page.collection('movie') %}
{% set collection = collection.intersect(movie_collection) %}
👍 3
last edited 01/09/23 by Vadym

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 94 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 184 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 146 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 60 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 254 1 year ago