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 }}
{{ $var := "" }}
{{ if .IsHome }}
{{ $var := "Hugo Home" }}
Var is {{ $var }}
{{ else }}
{{ $var := "Not Home" }}
Var is {{ $var }}
{{ end }}
Yes. Standard scoping issues are at play here and $var would still be empty outside the conditions because it was set empty globally.
Also for more advanced use cases such as storing parameter keys from a specific set of pages .Scratch is still the only way to store those and access them on the outside.