Where function Key when Key is frontmatter array

Please see below example:

Front Matter:

- Goeth Smalinsky
- Jordan Nevelin

In a partial:

{{ $authorsPages := where .Site.RegularPages "Params.authors" "Geoth Smalinksky" }}

The above returns false.

I believe correctly so, as “Params.authors” doesn’t equal a string, it’s an array of values, so, how then would I test this correctly?

I’ve tried various solutions, and am now simply ranging through $authorsPages and testing the Params with an if statement.

A la:

{{ $authorsPages := where .Site.RegularPages "Params.authors" "!=" nil }}
{{ range $authorsPages }}
  {{ if eq (index .Params.authors 0) "Jordan Nevelin" }}
     // Do stuff
  {{ end }}
{{ end }}

Which works fine, but it seems this could be much cleaner if I could write a better where statement.

Thank you for the assistance.

1 Like

In a similiar scenario I use this:

Front matter:

  - Hugo
  - Fritz
  - Lara

My where code to get all pages with tag Hugo:

{{ $myPages := where site.Pages "Params.tags" "intersect" (slice "Hugo") }}

(Should also work with .Site.RegularPages, I think.)

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.