When a variable is used in a FOREACH loop, it's value after the loop will be the last value of the loop.
For example, if we have a variable @letters containing a, b, and c:
[% SET x = "x" %]
[% x %] <!-- will print "x" -->
[% FOREACH x IN letters %}
[% x $]
[% END %]
[% x %] <!-- will print "c" -->
Contrasted with Perl:
my $x = "x";
foreach $x ( @letters ) {
say $x;
}
say $x; # will print "x"
I think a reasonable solution would be a configuration option ( or a keyword ) to localize the loop variable.