Nested where function doesn't work with ".Params.categories"

Hi,

It does. From the docs: collections.Where | Hugo

in

true if a given field value is included in a matching value; a matching value must be an array or a slice

In your case, "news" is neither an array nor a slice. Also, the given field value here is ".Params.categories", which (I’m assuming) is an array.

What you probably want instead is

Something like (untested)

{{ $posts := (where .Pages "Section" "post" )  }}
{{ $news := (where (where .Pages "Section" "post" ) ".Params.categories" "intersect" (slice "news") ) }}

{{ $notnews := $posts | complement $news | first 3 }}

slice "news" in this case turns "news", a string, to ["news"], an array containing "news"

Then you can {{ range first 3 $notnews }} .

1 Like