[Zope] Building tables from a db in dtml...

Tres Seaver tseaver@palladion.com
Sun, 27 Feb 2000 16:05:56 -0600


"Cornelis J. de Brabander" <brabander@fsw.leidenuniv.nl>
> Subject: Re: 
> 
> -----Oorspronkelijk bericht-----
> Van: Martijn Pieters <mj@digicool.com>
> Aan: jiva@devware.com <jiva@devware.com>; zope@zope.org <zope@zope.org>
> Datum: zondag 27 februari 2000 10:57
> Onderwerp: Re: [Zope] Building tables from a db in dtml...
> 
> [snip]
> 
> >(untested):
> >
> >  <table><tr>
> >  <dtml-in db_query>
> >    <dtml-if "_['count-value'] % 4 == 0"></tr><tr></dtml-if>
> >    <td><dtml-var value></td>
> >  </dtml-in>
> >  </tr></table>
> >
> >Now, I could be wrong and count-value is 1 based in stead of 0 based. In
> >fact, I believe it is, it would make sense anyway. Then you'd adjust the
> >logic slightly, something like (_['count-value'] - 1) % 4.
> >
> 
> Count-xxx does not change during the sequence, it simply gives the number of
> non-missing xxx-values in the sequence. Furthermore, refering to the
> response of Jim Sanford, the solution can do without integer or sting
> conversions:
> 
> (tested!!!)
> 
> <TABLE>
> <dtml-in objectValues>
> <TR><TD><dtml-var sequence-number></TD>
> <TD>
> <dtml-if "_['sequence-number']!=0 and _['sequence-number']%2==0">even
> <dtml-else> odd
> </dtml-if>
> </TD></TR>
> </dtml-in>
> </TABLE>

Check out (for this purpose, anyway) sequence-odd and sequence-even in the DTML
reference.

To answer the original poster::

  <dtml-if "_[ 'sequence-index' ] % 4 == 0">
    </tr><tr>
  </dtml-if>

should do fine.

And to emulate Cato,

  Agnosciti invalidi delendi est

("Invalid identifiers must be destroyed").  I _hate_ the "sequence-foo"
pseudo-identifiers in DTML, worse than any other feature of Zope.  The only
rational way to spell the above is::

  <dtml-if "sequence_index % 4 == 0">
    </tr><tr>
  </dtml-if>

but that won't work (without enclosing it in a <dtml-let> which aliases
'sequence-index' as 'sequence_index'.


-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com