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

Complex collection filter : taxonomy for page children

Started by Muut Archive 9 years ago · 1 replies · 1062 views
9 years ago

Hi !

I have two pages where I post items : blog (for normal blog posts) and files (for files like pdfs). Those two pages share a common taxonomy : I use tags to determine to which project a blog post or a file belongs (can be several projects at once).

Now I'd like to display two different lists on my project page : recent posts and recent files. I'd like to show only posts/files for that specific project. I thought it would be easy using Grav, but I'm stuck.

This doesn't work, as it seems the returned collection is an union of @page and @taxonomy instead of an intersection :

TWIG
{% set projects_last_posts = page.collection({'items':{'@page.children':'/blog', '@taxonomy.tag':'my_project'}}) %}
{% set projects_last_files = page.collection({'items':{'@page.children':'/files', '@taxonomy.tag':'my_project'}}) %}

It seems like a relatively simple use case, but reading the doc, I don't see how I can achieve this.

Help would be greatly appreciated !

Thanks,

Olivier

9 years ago

Hi Olivier,
Maybe you could try it with taxonomy.findTaxonomy()
You would have to use a second taxonomy like "category" to make it work correctly, though...
So, on all your files you could set "category:file" and "tag:my_project" and on the posts "category:post" and "tag:my_project"

Then on your project page:

TWIG
{% set projects_last_posts = taxonomy.findTaxonomy({'category':'post','tag':'my_project'}) %}
{% set projects_last_files = taxonomy.findTaxonomy({'category':'file','tag':'my_project'}) %}

Maybe this works for your use case?

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1323 9 years ago
Archive · by Muut Archive, 9 years ago
2 919 9 years ago
Archive · by Muut Archive, 9 years ago
2 4048 9 years ago
Archive · by Muut Archive, 9 years ago
1 2923 9 years ago
Archive · by Muut Archive, 9 years ago
3 1106 9 years ago