with
creates a local scope
[% x=10 y=20 %] [% with y=200, z=300 %] x is [% x %] [# 10 #] y is [% y %] [# 200 #] z is [% z %] [# 300 #] [% end %] [# y restored to 20, z is undefined #]--EOF--look inside...
Thus Spake Andy:
TT2 had the INCLUDE
directive which filled a template in a local variable
scope (a fancy way of saying that your existing variables don't get trampled
on). In TT3 we have a new with
command for creating a local scope. Inside
the with
...end
block we have two new variables defined, y
and z
.
All the other variables outside the block are also visible. Any new variables
added or existing variables changed inside the block will only persist until
the end of the block. At that point the local scope is discarded and the
outer scope restored (another fancy way of saying you get your old variables
back).