Range with pages with specific category

I’m trying to use ‘range’ but only want the pages where the ‘categories’ page parameter contains “Featured”. ‘Categories’ is a string array [“Featured”,“Cat2”,“Cat3”] and may or may not have “Featured” in it.
How can I go from {{ range site.RegularPages }} to only including “Featured” pages?

I think the documentation answers that:

See the in operator

Yeah. I know. I just can’t figure out how to get it right. Thanks for the link. I’ll keep trying.

You ask about range, I point you to where you say that you know? I don’t follow. Even less, since you do not post any code.

{{ range .Site.RegularPages }}
gets me a list of all pages, so that works.
I want to iterate through all the pages where ‘Categories’ contains “Featured”.
I’m trying something like:
{{ range where .Site.RegularPages “.Params.categories” in “Featured” }}
It doesn’t generate an error but neither does it get me any results.

The documentation does not provide a clear example of what you are trying to accomplish. @chrillek is correct that you need to use the where function, but you must compare using intersect, not in.

{{ range  where .Site.RegularPages ".Params.categories" "intersect" (slice "featured") }}

Thank you so much! I’ve been banging my head against this for hours. I’m still figuring out how all this works.

1 Like

Thanks for explaining that.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.