Range where in question

I have a list page template.

This range function returns a list of all pages with all tags in an array. Some of the pages have a “my-tag” in their tag list.

// works as expected
Test List 
<ul>
    {{ range .Pages }}
        <li>
            {{ .Page.Params.tags }}
        </li>
    {{ end}}
</ul>

I want to filter some of the pages, keep only those that have the specific “my-tag” tag.

// not getting expected results
Range Function
<ul>
    {{ range where .Pages "my-tag" "in" .Page.Params.tags }}
        <li>
            {{ . }}
        </li>
    {{ end}}
</ul>

However this second list is always empty. Is there in error in the range syntax? Thanks!

https://gohugo.io/functions/where/#use-where-with-intersect

Thank you, I have been reading the documentation and I do not find it clear. I have tried many variations now, I am posting because I am requesting help to understand what is going on.

{{ range where site.RegularPages "Params.tags" "intersect" (slice "my-tag") }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
2 Likes

Thank you, this code helps me achieve my goal.

Still after reviewing the docs again I am not certain why example two below works and not example one. It seems that in example two we are creating the slice just to use intersect. Could we have achieved a similar result using in?

// example one (doesn't work)
<ul>
    {{ range where .Pages ".Params.tags" "in" "my-tag" }}
        <li>
            {{ .Title }}
        </li>
    {{ end}}
</ul>
// example two (does work)
<ul>
    {{ range where .Pages ".Params.tags" "intersect" (slice "my-tag") }}
        <li>
            {{ .Title }}
        </li>
    {{ end }}
</ul>

No…