[Templates] naming conflict

Mark Mills mark@xodiax.com
Mon, 11 Mar 2002 14:06:37 -0500


> Thank you for your really fast answer.
>=20
> In my real examples, the loop is in a separate file, but I=20
> have to use [% PROCESS ... %], because inside the loop,=20
> I define some common variables, that I want to use later. ...
> So I need a different solution.

ah. Well, if you are setting other variables within those loops...

> The problem seems to be, that in the array-name 'i.array', TT doesn't
> interpret i as a hash-name (with a array as value for key 'array') but
> wants to interpret i with the scalar variable defined earlier in the
> FOREACH loop.

Well, the honest truth is that TT isn't perl. The Stash doesn't keep
separate "branches" in its namespace for hashes vs. arrays vs. scalars.
One name, one variable. And the Stash doesn't support any sort of =
localize.

I think you are honestly going to have to institute some sort of naming
policy where you don't reuse variables.=20

* pause for a late lunch with the boss *
(I notice someone else answered much the same as I did above.)

Hey, come to think of it, if you have an array of hashes Stash localizes
within the FOREACH... it promotes the hash keys to variables within the
block without stomping on external variables. Maybe you can use that
for a workaround?
[% i =3D 3 %]
[% INCLUDE i %]
i =3D [% i +%]

[% BLOCK i %]
[% FOREACH [{i=3D>1,b=3D>3},{i=3D>2,b=3D>4}] %][% i; b %] [% END +%]
[% END %]

Too bad I don't see a way to get Iterators to return their current item
off of the localized "loop" variable they create.=20

--mark