Help with dtml-let & dtml-if
Hello: I'm not getting dtml-let. I use it to create a variable that I can access, correct? Say I want to initialize a counter, and change it from 0 1 each iteration of a loop. This will print out rows of a table with alternating background colors: <dtml-let x=0> </dtml-let> <dtml-in "getElementsByTagName('book')" > <dtml-if x==0> <tr bgcolor="DDEEAC"> <dtml-else> <tr> </dtml-if> write out some html </tr> <dtml-if x==0> <dtml-let x=1> </dtml-let> <dtml-else> <dtml-let x=0> </dtml-let> </dtml-if> </dtml-in> </table> </dtml-with> The let and if syntax is not good, and I can't read anywhere on how you would accomplish this type of construct. -andy
Hi Andrew! On Wed, 29 Mar 2000, Andrew Diller wrote:
Hello:
I'm not getting dtml-let. I use it to create a variable that I can access, correct?
Say I want to initialize a counter, and change it from 0 1 each iteration of a loop.
This will print out rows of a table with alternating background colors:
<dtml-let x=0> </dtml-let>
<dtml-in "getElementsByTagName('book')" >
<dtml-if x==0> <tr bgcolor="DDEEAC"> <dtml-else> <tr> </dtml-if>
write out some html
</tr>
<dtml-if x==0> <dtml-let x=1> </dtml-let> <dtml-else> <dtml-let x=0> </dtml-let> </dtml-if>
</dtml-in> </table> </dtml-with>
<dtml-let> tags only set that variable within the <dtml-let>context</dtml-let> tags. The task you wish to do would much easily done using the variables set by dtml-in. Eg <dtml-var sequence-index> will print out the 'count' if you like for the list. <dtml-if sequence-start> </dtml-if> (from memory?) will evaluate if it is the first iteration of the loop. <dtml-if sequence-even> and <dtml-if sequence-odd> will evaluate odd and even iterations of the loop, which is what it apears you want todo. Check out the zope quick reference document for documentation on this http://www.zope.org/Members/ZQR. Cheers, Benno
Andrew Diller wrote:
Hello:
I'm not getting dtml-let. I use it to create a variable that I can access, correct?
Yes.
Say I want to initialize a counter, and change it from 0 1 each iteration of a loop.
Let me warn you, you are allready thinking too procedurally. Remeber DTML is a _template_ language.
This will print out rows of a table with alternating background colors:
<dtml-let x=0> </dtml-let>
<dtml-in "getElementsByTagName('book')" >
<dtml-if x==0> <tr bgcolor="DDEEAC"> <dtml-else> <tr> </dtml-if>
write out some html
</tr>
<dtml-if x==0> <dtml-let x=1> </dtml-let> <dtml-else> <dtml-let x=0> </dtml-let> </dtml-if>
</dtml-in> </table> </dtml-with>
Let defines a new scope for variables, the scope being defined by the let block. Each time you use the let tag, you are creating and then immediatly destroying the scope of your variable. If you want to use 'x' in your DTML code, that code must be contained in the let block that defines x. What you are doing is easily done using the 'sequence-even' attribute. <dtml-in "getElementsByTagName('book')" > <dtml-if sequence-even> Print stuff for even rows <dtml-else> Print stuff for odd rows. </dtml-if> </dtml-in> -Michel
Thanks, of course, this worked exactly as I needed.
Say I want to initialize a counter, and change it from 0 1 each iteration of a loop.
Let me warn you, you are allready thinking too procedurally. Remeber DTML is a _template_ language.
What you are doing is easily done using the 'sequence-even' attribute.
<dtml-in "getElementsByTagName('book')" > <dtml-if sequence-even> Print stuff for even rows <dtml-else> Print stuff for odd rows. </dtml-if> </dtml-in>
-Michel
participants (3)
-
Ben Leslie -
dillera@isc.upenn.edu -
Michel Pelletier