Iterate over a list of Params in layout

I’m displaying the categories of my blog in a menu. Now, I’d like to filter them.

I define a parameter in my config:

menuCategories = [ "Category 1", "Category 2" ]

And then use it as a filter in my layout:

{{ $whitelist := .Site.Params.menuCategories }}
{{ range .Site.Taxonomies.categories }}
{{ if (in .Page.Title $whitelist) }}
  <li class="tag"><a title="{{ .Page.Title }}" href="{{ .Page.Permalink }}">{{ .Page.Title }}</a></li>
{{ end }}
{{ end }}

However, the if statement never evaluates to true.
Is whitelist not a list here that I can use in on?

Turns out I’m just an idiot. I got the order of the arguments wrong.

{{ if (in $whitelist .Page.Title) }}

works fine.

2 Likes