[Zope] dtml-in question

Duncan Booth duncan@rcp.co.uk
Wed, 2 Aug 2000 09:39:40 +0000


> I had the same problem and found out there is no way yet of making dtml-in
> with multiple conditions. Instead I had to do dtml-if's and make my own
> counter and previous/next attributes to handle the batches.
> 
One way to simplify this is to use two dtml-in loops. The first one 
filters out the items you want to include, then the second one just 
displays all the items in the filtered loop.

So instead of:
   <dtml-in sequence><dtml-if "somecomplexcondition">
      messing around with counters and stuff goes here...
   </dtml-if></dtml-in>

You have something like:
   <dtml-let seq="[]">
   <dtml-in sequence><dtml-if "somecomplexcondition">
       <dtml-call "seq.append((_['sequence-key'], _['sequence-
item']))"
   </dtml-if></dtml-in>

   <dtml-in seq> Put your real loop body here. </dtml-in>
   </dtml-let>

The second sequence then has the correct counter, and you can 
use the next/prev batches on it as well if you want.

When building the second sequence you have a choice of how to 
structure it. If you simple append sequence-item, this should work, 
unless the sequence items are two element tuples. If you append a 
tuple as shown this should work every time. It can also be useful to 
calculate a new key, for example if you wanted to sort the list on 
more than one field you could build a key from the sorted fields.

The main downside to this scheme is that you have to process the 
whole list, which could be annoying if you just want a small batch 
from the front of a long list.

-- 
Duncan Booth                                             duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan