darren chamberlain wrote:
> Someone requested something similar back in September, and I made a
> patch that created a new directive, DO, that created a new Stash for
> the processed file.
I've got a new implementation of the Stash for TT3 which implements
the localisation in a slightly different manner.
The primary reason for doing this was to implement copy-on-write. This
avoids the overhead of localising the stash until a variable value is
changed, which sometimes never happens and hence never needs to be done.
A secondary benefit is that it should be easy to create a detached stash
as a specialised kind of localisation. The effect would be to create a
new, empty variable namespace, or one containing some pre-declared
variables and nothing else. A useful feature, however, would be that
the stash would still maintain a reference to the parent stash scope,
allowing you to explicitly import further variables from the caller's
namespace if you need to.
> [% DO foo %]
> bar = "zot"
> [% END %]
I think you mean:
[% DO foo bar="zot" %]
Syntax aside, I can see how it could be a useful feature. Global
variable clash is, IMHO, one of the weaker features of TT that should
be addressed in TT3. It's all too easy, particularly in larger
systems with many variables, to accidentally use a variable twice
in different templates and wreak havoc. Being able to sandbox templates
into separate variable spaces would definately help.
As Darren points out, it's a non-trivial patch to add new language
features because you have to re-compile the parse grammar. This is
another ugliness that is going away in TT3. Adding new directives
with custom behaviours will be much easier.
In fact, DO may well appear in TT3 as a core language directive (or
one that can be enabled by some option), but I've got half a memory
that I had a different use intended for it. Need to think more about
that.
Cheers
A
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.ourshack.com/mailman/listinfo/templates