[Zope] Different Sorting Methods using DTML-IN

Joel Burton joel@joelburton.com
Sun, 11 Aug 2002 12:42:09 -0400


On Fri, Aug 09, 2002 at 10:39:40PM +0200, Dieter Maurer wrote:
> Alexander M Hottenstein writes:
>  > I am attempting to use several different sorting variables on a dtml-in
>  > of one type of object. Depending on several booleens that determine
>  > which sorting methods will be used. I know that I cannot use a dtml-if
>  > to determine which dtml-in to use, but do not want to have several
>  > different blocks of code for each sort that I use.
> Look at "sort_expr" (a "dtml-in" attribute).
> 
> As an example, look at how the ZMI (Zope Management Interface) does
> this (--> OFS/dtml/main.dtml).


As a more general tip, when you feel frustrated by not being able
to have a <dtml-in> inside a <dtml-if>, you can follow this pattern:

<dtml-if xxx>
  <dtml-set list="sorted-some-way">
<dtml-elif yyy>
  <dtml-set list="another-way">
<dtml-else>
  <dtml-set list="yet-another-way">
</dtml-if>

<dtml-in list>
  ...
</dtml-in>


(<dtml-set> is just a shorthand for the long-winded <dtml-call
"REQUEST.set('list', 'xxxx')"> -- you can find it on zope.org or just
use the traditional REQUEST.set way.

Dieter's solution is better for your exact problem, but in cases where
you want the list filtered differently for different cases, etc., the
above is a flexible setup.

- J.



-- 

Joel BURTON  |  joel@joelburton.com  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant