Hi, from al the discussion about #mascros vs. #subroutines
it appears to me that the need to be able limit the scope
of a variable in the context to a particular portion of
the template is more important than I prevously thought.
So I am proposing adding a new directive (it could be optional)
if you want. Here is the proposal:
#begin ( $a $b ... )
.....
#end
$a, $b and so on will be new. In the sense that
you new to do a #set operation before the variable
is available, and any values given to the variables
will be reverted once #end is reached.
So for example:
----------------------------
#set ($a = 1)
#set ($b = "valid")
#begin ($a $b)
#set ($a = 2)
The value is of a is $a
#if($b)
b is valid
#else
b is invalid
#end
#end
The value is of a is $a
#if($b)
b is valid
#else
b is invalid
---------------------------
it should generate:
---------------------------
The value is of a is 2
b is invalid
The value is of a is 1
b is valid
---------------------------
This proposals is completely indepedent on the discussion about
how to do macros and so on. And is based in the current Context
implementation. The schetch of the implementation is as follows:
To render the body of the directive:
- Remove any variable with the same names from the Context and
keep their values in the execution stack.
- render the block
- Restore Context the the original values of those variables
A very simple directive indeed.
Notes:
1) I have limited the declaration to not do initialization
as to keep the directive simple.
2) I allowed multiple declaration since it would came for free.
Any comments, opinions,
Jose Alberto