faqts : Computers : Internet : Web Servers : Zope : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 9 people (78%) answered Yes
Recently 5 of 7 people (71%) answered Yes

Entry

Is there an easy way to simulate the functionality of a while loop in DTML?

Jul 27th, 2000 23:21
unknown unknown, Patrick Lewis


This is real ugly, but you asked (untested, but you get the idea):
<dtml-try>
  <dtml-in "_.range(1000)">
    <dtml-if whileCondition>  <!-- Your logic test -->
      <!-- Do stuff in while loop -->
    <dtml-else>
      <dtml-raise type="conditionFalse">errormsg</dtml-raise>
    </dtml-if>
  </dtml-in>
<dtml-except conditionFalse>
  <!-- Fall out of 'while' loop.  -->
<dtml-else>
  <dtml-raise type="RangeError">Oops! Exception never 
raised.</dtml-raise>
</dtml-try>
This only works if the loop will cycle less than 1000 times.  Needless 
to say, this is done a lot easier in Python.