Reputation: 3149
I have this code: http://play.golang.org/p/mPX1azLhlg but why I can't change my $foo
value? How I supposed to do this?
Upvotes: 1
Views: 4359
Reputation: 33
This seems to have been updated in go1.11: https://golang.org/doc/go1.11#text/template
Modifying template variables via assignments is now permitted via the = token
So you need to change {{$foo := 1}}
to {{$foo = 1}}
https://play.golang.org/p/hqWClmZfjcx
Upvotes: 3
Reputation: 180
A variable's scope extends to the "end" action of the control structure ("if", "with", or "range") in which it is declared, or to the end of the template if there is no such control structure.
(http://golang.org/pkg/text/template/)
Upvotes: 2