`where` function's "not in" operator doesn't include booleans, or the values that have not been "set". A bug?

I was trying to filter the “non-hidden” pages with the where function but couldn’t get the desired result.

Here’s what I tried initially:

{{ $paginator := .Paginate (where .Pages "Params.hiddenPage" "not in" (slice true "true"))}}

I had four pages with the hiddenPage param actually set and several others which didn’t have it.
Two of the pages had the param set to true/false as strings, the other two had true/false as booleans.

However, only the page with hiddenPage set to string false was returned in this case. And changing the where condition operator to in returned only the page with hiddenPage set to string true.

Is this the desired behavior? If yes, could you please point me to the right way to do this? If not, I would open a GH issue for the same.Thanks.

PS: I know the slice (with elements of different types) isn’t the issue because it works in this case:

{{ if .Params.hiddenPage | or .Params.noindex | in (slice "true" true) }}

It seems like the where function’s in and not in operators should handle this:

{{ range where site.RegularPages "Params.hiddenPage" "not in" (slice true "true") }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}

So, yes, log an issue.


{{ range site.RegularPages }}
  {{ if not (in (slice "true" true) .Params.hiddenPage) }}
    <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
  {{ end }}
{{ end }}

Does this note regarding “unset” fields have to do anything with where not returning other pages where the field is not set and only the use of slice is the problem? @jmooring

I’m not sure that I understand your question, but if you want to find pages with or without a front matter variable, compare to nil.

1 Like