Hello, I’m checking if an element is included in an array but it’s not working… I’m out of ideas of what can be the problem
this is the code in the layout>
{{ $v := substr .Permalink -3 -1 }}
{{ printf "%#v" $v }}
{{ printf "%#v" .Site.Params.lang }}
{{ in .Site.Params.lang "es" }}
{{ in .Site.Params.lang $v }}
output:
"es" []interface {}{"en", "es"} false false
url: http://localhost:1313/lang/es/
config.yml:
[params]
default_lang = "en"
lang = ["en", "es", "it"]
1 Like
bep
2
Could you print the type of one of the values in .Site.Params.lang
? printf “%T” …
code:
{{ $v := substr .Permalink -3 -1 }}
{{ printf "%#v" $v }}
{{ printf "%#v" .Site.Params.lang }}
{{ printf "%T" $v }}
{{ index .Site.Params.lang 0|printf "%T" }}
{{ in .Site.Params.lang "es" }}
{{ in .Site.Params.lang $v }}
output:
"es" []interface {}{"en", "es"} string string false false
bep
4
It’s a bug:
It might behave differently between JSON, TOML and YAML, though.