[Zope] <!--#local--> and <!--#set--> (was Re: Proper way to set variables)

Phillip J. Eby pje@telecommunity.com
Wed, 08 Sep 1999 17:16:39 -0500


At 02:02 PM 9/8/99 -0500, John Goerzen wrote:
>Heh, feels strange to reply to myself, but as I got no replies before, 
>maybe I need to elaborate a bit.  The original question is below.
>
>My main confusion is just how do I set a variable that is dynamically
>scoped without having to use dtml-with or dtml-let, both of which
>require matching closing tags?
>

FYI, I have just written a patch for DT_Let.py that adds two new tags,
'local' and 'set'.  They are used like this:

<!--#local myvar1="0" myvar2=somevar-->


<!--#set myvar1="myvar1+myvar2"-->
...
<!--#set myvar2="myvar2+1"-->

<!--#/local-->


Both <!--#local--> blocks and <!--#set--> tags are dynamically scoped and
<!--#set--> can be used anywhere as long as there is an enclosing
<!--#local--> block defining the variable you want to set.  You can only
set variables which are defined by the innermost <!--#local--> block, but
you can reset their value any number of times, even within the same
<!--#set--> tag.

I am currently testing this code in an alpha app, but will be submitting it
some time in the near future to Digital Creations for consideration of
inclusion in future Zope versions.