Simple front matter array iteration conditional

I have front matter like this:

---
title: Button
platforms:
- web
- android
---

and a single.html template file where I want to conditionally display a piece of content if certain values are missing in .Params.platforms array. For example, if “ios” is not listed in the front-matter, then I want to display a piece of content similar to:

{{ with .Params.platforms }}
{{ range $index, . }}
{{ if ne $index "android" }}
<div>Android is not supported for {{ .Params.title }}</div>
{{ end }}
{{ end }}
{{ end }}

However this doesn’t seem to work and displays the message anyway. I’m assuming this is fairly easy, I’m just limited in my logic understanding?

I could also be doing this way wrong, so please don’t take my code above as something I’m trying to make work. I mainly just want to arrive at my goal of displaying statements if certain values/strings are missing from the front-matter array.

You can use in

{{ with .Params.platforms }}
   {{ if not (in . "android") }}
   [ code ]
  {{ end }}
{{ end }}
3 Likes

Perfect! Thanks so much!

1 Like