[Zope-dev] ANN: "Let" tag available for download

Phillip J. Eby pje@telecommunity.com
Thu, 10 Jun 1999 13:44:49 -0500


Do you find nesting <!--#with "_.namespace()"--> tags too verbose?  Don't
like cluttering your REQUEST object with temporary variables?  Want to get
at weirdly named DTML variables from Python expressions without having to
play _[] and _.render() tricks?  Then check out:

http://telecommunity.com/DT_Let.py

It's a new tag that lets you create blocks like:

<!--#in "1,2,3,4"-->
<!--#let num=sequence-item 
         index=sequence-index
         result="num*index"-->
<!--#var num--> * <!--#var index--> = <!--#var result-->
<!--#/let-->
<!--#/in-->

Which yields:

1 * 0 = 0
2 * 1 = 2
3 * 2 = 6
4 * 3 = 12

Notice that quoted arguments are treated as expressions, and unquoted
arguments are treated as DTML names.  Evaluation is in sequence with the
result of earlier assignments available to later ones.  Later assignments
can also override earlier ones, which can be helpful for longer
step-by-step calculations.  The variables thus set are in effect for the
life of the <!--#let--> block.

To use this wonderful, lifesaving tag, just stick the module somewhere that
Python can find it, and put an "import DT_Let" somewhere in your code where
it will get executed before you need it.  Permission is hereby granted to
the wonderful folks at DC to incorporate this into Zope.  The point of
making this was to reduce verbosity for heavy DTML scripting, though, so if
you do put it in, *please*, *please* don't rename it to #with-namespace or
#with-variable-values or anything like that, okay?  :)  Thanks.