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