Please, help. This code did not work in any configuration:
{{ range where .Site.Pages ".Params.tags" "in" "tag_to_display" }}
{{ . }}
{{ end }}
I tried intersect
instead in
with same no result. I tried to use variable $tag_to_display_var := slice "tag_to_display"
instead of "tag_to_display"
string - same empty result.
My temporary workaround is
{{ range where .Site.Pages ".Params.tags" "intersect" $.Page.Params.foo.array_of_tags_to_display }}
{{ . }}
{{ end }}
But I need to use hardcoded string, not array of tags from the frontmatter. I need to output pages with a specific both category and tag.
The brilliant code could look like this (non-working code!):
{{ range where
(where .Site.Pages ".Params.categories" "in" "category_to_display")
".Params.tags" "in" "tag_to_display"
}}
{{ . }}
{{ end }}
I know that I can use Taxonomies but my finish aim is to get pages with the both tags and categories. Taxonomies didn’t give this possibility.
Now I use this code to get pages with both the tags and the categories:
{{ $filtered := "" }}
{{ $set1 := where .Site.Pages ".Params.categories" "intersect" $.Page.Params.foo.categories }}
{{ $set2 := where .Site.Pages ".Params.tags" "intersect" $.Page.Params.foo.tags }}
{{ if and (gt (len $set1) 0) (gt (len $set2) 0) }}
{{ $filtered = $set1 | intersect $set2 }}
{{ else if (gt (len $set1) 0) }}
{{ $filtered = $set1 }}
{{ else if (gt (len $set2) 0) }}
{{ $filtered = $set2 }}
{{ end }}
{{ with $filtered }}
{{ . }}
{{ end }}
Thanks a lot!