Question about variable overwrites in Hugo 0.48

So, the new feature allows variable overwrites, but there are still scoping in play here – similar to how it would work in plain Go code. To cut a long story short, you need to initialize the variable in (or on the outside of) the scope where you intend to use it. Set it to some empty value if you’re not sure that it will be used.

{{ $var := "" }}
{{ if .IsHome }}
	{{ $var = "Hugo Home" }}
{{ end }}
Var is {{ $var }}
3 Likes