[Zope] Looping in DTML

Chris Beaven chris@d-designz.co.nz
Tue, 25 Feb 2003 11:21:46 +1300


<dtml-in "[{'ordno': 1, 'order': 'tacos'}, {'ordno': 2, 'order': 'fries'}]">
<dtml-var expr="_['sequence-item']['ordno']" fmt="%02d"><dtml-var 
expr="_['sequence-item']['order']" fmt="%8s">
</dtml-in>

or Python:

output = ''
records = [{'ordno': 1, 'order': 'tacos'}, {'ordno': 2, 'order': 'fries'}]
for record in records:
  output = '%s%02d%8s\n' % (output, record['ordno'], record['order'])
return output


Flavio wrote:

>Hi,
>
>I would like to know if someone can help me with this one. I need to
>loop by
>a set of variables so I can insert then into my database.
>I started looking at the following example:
>
><dtml-in "16,21,3,49">
>item# <dtml-var sequence-index>,<dtml-var sequence-number> = <dtml-var
>sequence-item>
></dtml-in>
>
>and it's output 
>
>item# 0,1 = 16
>item# 1,2 = 21
>item# 2,3 = 3
>item# 3,4 = 49
>
>So.. I changed the <dtml-in> tag by repalcing the fixed values with one
>of
>my variables. It did worg fine :
>
><dtml-in description>
>   <dtml-var sequence-item>
></dtml-in>
>
>The problem is that I need more than one column per line of data 
>E.G.
>
><dtml-in (ordnumber,description)>
>  <dtm-var sequence-item>
></dtml-in>
>
>output
>
>01  Freight
>02  Delivery
>
>Is there a way I can do that ?
>
>thanks,
>
>Flavio
>
>
>
>---
>
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.458 / Virus Database: 257 - Release Date: 2/24/2003
> 
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://mail.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - 
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
>  
>