Get frontmatter key values from all pages in a section, without duplicates

Hi! I’m new to Hugo, so forgive me if this is an easy fix. Is there a way to get all values of a specified frontmatter key from all pages within a section? i.e. I have this directory structure:

  • section-1
    • _index.html
    • a.html
    • b.html
  • section-2
    • _index.html
    • c.html

Inside each page I have a frontmatter variable authors:

- Author 1
- Author 2

How can I loop through all these pages and grab the authors, removing any duplicates along the way?

Welcome to the forums @devinhalladay

If I’m understanding you correctly, you could do something like

{{ $authors := slice }}
{{ range where .Pages "Section" "section-1" }}
  {{ $authors = $authors | append .Params.authors }}
{{ end }}
{{ $authors | uniq }}
1 Like

That’s perfect, thank you @zwbetz!