Closed
Description
Given this template snippet:
{{ $v := "init" }}
{{ if true }}
{{ $v := "changed" }}
{{ end }}
v: {{ $v }} {{/* => init */}}
The inner $v
is not visible on the outside. :=
does hint that this is a new variable.
Trying
{{ $v = "changed" }}
Gives
unexpected "=" in operand; missing space?
This is probably as designed, but it would be really nice if there was a way to get the changed $v
outside of the conditional.
This is the #1 template question we get over at Hugo (https://github.com/spf13/hugo). We have added a hack to workaround it for now ...