[Templates] naming conflict
Mark Mills
mark@xodiax.com
Mon, 11 Mar 2002 12:09:53 -0500
> I'm using TT 2.05 on AIX 4.3.3.
> I have a problem with conflicting names. I use something like the
> following:
>=20
> ----
> [%
> i.array=3D[ 1, 4, 7, ]
> %]
> xxx[% i.array %]yyy[% i.array.1 %]zzz
> [%- FOREACH i=3D[ -10 .. 10 ] -%]
> [%- END -%]
> [%
> i.array=3D[ 1, 4, 7, ]
> %]
> xxx[% i.array %]yyy[% i.array.1 %]zzz
> ----
>=20
> After the FOREACH-loop, the array i.array is no longer=20
> defined. Surely, I
> can use other names, but they would be less intuitive in my=20
> real examples
> and I would have to change quite a lot of them.
> Is there a way to solve this naming conflict. Is there a way=20
> to undefine
> the variable i after the loop only with a TT-directive (no perl code)?
There isn't a localization command that I know of but you can use
BLOCK to your advantage for these sorts of issues. INCLUDE makes a
copy of the Stash and so protects you from changes made inside blocks.
(To an extent, anyway). I know that isn't what you are asking for but
it might help.
--mark
[% i =3D 3 %]
[% INCLUDE i +%]
i =3D [% i %]
[% BLOCK i %]
inside i=3D[% FOREACH i =3D [ 10..20 ] %][% i %] [% END +%]
[% END %]