[Zope] I seem to be missing a "break" DTML ta

Tres Seaver tseaver@digicool.com
Wed, 10 May 2000 17:55:08 -0400


"Evan Simpson" <evan@digicool.com> wrote:
> 
> ----- Original Message -----
> From: Dennis Nichols <nichols@tradingconnections.com>
> > Let's say that I want to make a list of nodes from the top down (the
> > reverse of PARENTS). Easy enough:
> >
> > <dtml-call "REQUEST.set('topdown', [])">
> > <dtml-in PARENTS skip_unauthorized>
> >    <dtml-call "topdown.insert(0, _['sequence-item'])">
> > </dtml-in>
> >
> > However, what I really want to do is quit reversing when I get up
> > to a particular level, say the point at which I get to my Portal
> > folder.
> >
> > But I find no documentation on a break command. Is there any such
> > construct in dtml?
> 
> 'Fraid not.  The best I can think of offhand is:
> 
> <dtml-call "REQUEST.set('topdown', [])">
> <dtml-call "REQUEST.set('loopdone', 0)">
> <dtml-in PARENTS skip_unauthorized>
>   <dtml-unless loopdone>
>    <dtml-call "topdown.insert(0, _['sequence-item'])">
>    <dtml-if "...last iteration...">
>      <dtml-call "REQUEST.set('loopdone', 1)">
>    </dtml-if>
>   </dtml-unless>
> </dtml-in>

This is really a good case study for when to shift from DTML to Python:
my take is that anytime you need "odd" control structures, abandon
DTML.  A PythonMethod would look like::

  Parameter list:   source_list  break_object

  Body:

     result = source_list
     result.reverse()
     try:
          return result[:result.index(break_object)]
     except:
          return result

-- 
=======================================================================
Tres Seaver          tseaver@digicool.com           http://www.zope.org
Digital Creations    "Makers of Zope"