Select a category in collections


Some problem to resolve a query when I try to use this code for a collections solution.

page.categories -> is the result for the name of a category

For post page this kind of code is right and efficient :
{% for post in site.categories[page.categories] %}

But I would like use this sentence for collections as :slight_smile:
{% for product in site.products[page.categories] %}

So in my head I think a “where” condition with filter will be :blush:
{% assign sorted-products = site.products | where: "categories", page.categories %}
{% for product in sorted-products %}

Perhaps it’s impossible to execute this outside Post function ?

Thanks for an advice


I believe this isn’t possible in Jekyll’s current state.
The way categories work with site.posts and collections isn’t the same.

The inconsistencies are documented here… I believe the goal is for Jekyll 4.0 to unify posts, pages, and collections so they behave similar.

Hello mmistakes,

Thanks for the reply and this information.
It will be great that we could use this principe in the futur (v4).

So I get back to my version using Post system.