If in checking for number in array in range not working

I have the following array set {{ $the_features := (slice "10" "20" "30") }} in a partial template file

A features.toml exists within the data folder and contains a multi dimensional array each array contains a .number key with a number value such as 10

I have a range looping over the features data and trying to check if any of the .number values match the array values above

This isn’t returning anything.

 {{ range .Site.Data }}

    {{ range .features }}

        {{ if in .number $the_features }}
          {{ . }}
        {{ end }}

    {{ end }}

 {{ end }}

What’s wrong with this if condition?

This however works, which illustrates what i’m trying to match.

          {{ if eq .number 10 }} // .number here is 10 so 10 equals 10.

            {{ .number }}

          {{ end }}

Thanks

I think I figured it out, the numbers in the data file weren’t wrapped in double quotes, while the numbers in the $the_features array were wrapped in quotes making them strings?

[[features]]
  number = 10
  .....

So wrapping the numbers with quotes in the data file solved this. Any followups with more details on in and eq and what they match would be great.

Thanks

1 Like