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

Taxonomy filtering not working

Solved by pamtbaau View solution

Started by Danilo Puchelt 4 years ago · 4 replies · 796 views
4 years ago

Hello, I'm trying to filter for category and tag in a news collection. How do i get this to work? The news getting displayed but not filtered at all:

TXT
---
content:
    items:
        '@page.children': '/news'
        '@taxonomy': {category: [Blog], tag: [Spielbericht]}
    leading: 0
    columns: 1
    limit: 5
    order:
        by: date
        dir: desc
    show_date: true
    pagination: true
    url_taxonomy_filters: true
---

I've also tried the different variants described here: https://learn.getgrav.org/17/content/collections#page-collections without any effect.

4 years ago

@dapu,

See 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]
👍 1
4 years ago

@dapu, Any progress you might be able to share?

4 years ago

I've tried this:

YAML
---
content:
    items:
        '@page.pages': /news
        '@taxonomy':
            category: Blog
            tag: Spielbericht
    leading: 0
    columns: 1
    limit: 5
    order:
        by: date
        dir: desc
    show_date: true
    pagination: true
    url_taxonomy_filters: true
---

But it's not working. The blog list is showing all of the news pages. It looks like the taxonomy is completely ignored. When I use the taxonomy filtering directly on the collection it works:

TWIG
// user/themes/theme_name/templates/blog_list.html.twig
{% set collection = page.collection( {'items':{'@taxonomy':{'category': 'Blog', 'tag': 'Spielbericht'}}} ) %}
4 years ago Solution

@dapu, As said before, a collection definition containing multiple collections combines the results of all defined collections.

The following collection contains all child pages of page /news plus all pages with category: Blog and tag: Spielbericht.
Meaning: If all taxonomy pages are in folder /news, the taxonomy filter has no effect, because all pages below /news are already included in the collection.

YAML
content:
    items:
        '@page.pages': /news
        '@taxonomy':
            category: Blog
            tag: Spielbericht

See the docs on @page.children:

@page.children - Children of a specific page
This collection takes a slug route of a page as an argument and will return all the published children of that page:

YAML
content:
items:
'@page.children': '/blog'

An alias of '@page.pages': '/blog' is also valid. Using '@page': '/blog' is deprecated as its meaning can change in the future.

Pay attention to the last paragraph which states that @page.pages: /blog is an alias for '@page.children': '/blog'

If above does not answer your question, then what is your interpretation of your own collection definition and what result do you expect?

👍 1
last edited 03/16/22 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 97 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 185 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 148 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 61 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 255 1 year ago