Where function with case-insensitive and reverse match

I would like to use the where function as a case-insensitive match and find my string anywhere in the slice. My example code is below.

{{ c := where .Site.Pages “.Params.tags” “in” $tag }}

So, I would like to find all pages with string $tag included the .Params.tags.

But I can’t figure out how to make the comparison case-insensitive. Also, the where function checks for the .Params.tags included in string $tag. But I would like to check if $tag is included in .Params.tags.

I could use a whole bunch of code to do this but I wonder if there is a simple solution.

Written from my phone, so not tested. But try:

{{ $pages := slice }}

{{ range .Site.Pages }}
  {{ if in (lower .Params.tags) (lower $tag) }}
    {{ $pages = $pages | append . }}
  {{ end }}
{{ end }}

{{ range $pages }}
// ...
1 Like


Thanks a lot. Your code works great! This saved me a lot of time.

The only change I needed was to add a $ to the second line because I was in a local context. The line now looks like this:

{{ range $.Site.Pages }}

Best Wishes,


1 Like