Skip to content

Loop iterator variables not localized within the loop #317

@kylemhall

Description

@kylemhall

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions