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


#1

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 }}

#2

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

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

For now you will have to use .Scratch https://gohugo.io/functions/scratch/