Variable not globally nested, variable cannot be applied with if func

Why is $lang not globally nested?

{{ $langVar := index .Site.Data.lang .Site.LanguageCode }}
{{ if eq $langVar “” }}
  {{ $lang := index .Site.Data.lang .Site.LanguageCode }}
{{ else }}
  {{ $lang := index .Site.Data.lang “en” }}
{{ end }}

It’s a Go thing: Hugo + Go 1.11 hype thread

This recent post might help: Scoping a variable outside of and if statement (or two)

For now you will have to use .Scratch Scratch | Hugo

1 Like