On Thu, 3 Jul 2014 13:46:15 -0400
George <g_adam...@hotmail.com> wrote:

>     [% FOREACH p IN presidents %]
>     Name: [% p.first_name %] [% p.last_name %]<BR>
>     [% END %]
> 
>     [% FOREACH presidents %]
>     Name: [% first_name %] [% last_name %]<BR>
>     [% END %]
[...]
> In the first case, "George" has no last name, so no value is
> printed.  In the second case, it appears "George" inherits the
> "last_name" value from the previous iteration.
> 
> Is this the intended operation?  

Not sure if it's intended, but the reason it happens is because there
isn't actually any scoping in FOREACH loops.  The second form just sets
variables in the stash based on the properties of your items.  If the
property isn't there, the variable doesn't get set (or unset).

I guess it could be fixed by having the FOREACH keep track of every
variable it set for the iteration, and then unset each of them before
continuing to the next iteration.


-- 

C. Chad Wallace, B.Sc.
The Lodging Company
http://www.lodgingcompany.com/
OpenPGP Public Key ID: 0x262208A0


_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to