[Zope] newbie question: nested loops

David J. C. Beach beach@verinet.com
Thu, 22 Jul 1999 14:01:17 -0600


I just started using Zope this week, so I'm pretty wet behind the
ears, so if anyone could answer these questions, I'd appreciate it.

I'm trying to write a nested loop in DTML and am running into some
difficulties.  The goal is to loop over the elements of a "lines"
property of a folder and lookup those names (which are the names of
subfolders), and then repeat this process in a inner-loop (on the
subfolders) to lookup the names of documents in those subfolders.

The object structure looks something like this:

/home (property users=['user1', 'user2'])
  |
  +--/user1 (property publish=['object1', 'object2'])
  |    |
  |    +---object1 (DTML Document)
  |    |
  |    +---object2 (DTML Document)
  |
  +--/user2 (property publish=['this', 'that'])
       |
       +---this (DTML Document)
       |
       +---that (DTML Document)

The goal here would be to iterate over the users in the outer loop and
then to iterate over their published documents in the inner-loop (thus
getting all published documents from all users).

I've got a DTML method (sitting in /home) that looks something this:

(NOTE: I'm using a version of Zope which doesn't support the new "let"
tag -- I'm guessing that the "let" tag is syntactic sugar for a "with
_.namespace()" construct.)

------------------------list_docs------------------------------
<table>
  <tr>
    <th>Id</th>
    <th>Name</th>
    <th>Author</th>
  </tr>

<!--#in users-->
<!--#with "_.namespace(user=_[_['sequence-item']])"-->

<!--#in "_['user'].publish"-->

<!-- I think this next line is a serious case of wishful thinking -->
<!--#with "_.namespace(doc=getattr(_['user'], _['sequence-item']))"-->

  <tr>
    <td><!--#var "_['doc'].id"--></td>    <-- show document id -->
    <td><!--#var "_['doc'].title"--></td> <-- show document title -->

<!--#/with-->
<!--#/in-->

    <td><!--#var "_['user'].title"--></td> <-- show user name == author -->
  </tr>

<!--#/with-->
<!--#/in-->

</table>
------------------------------------------------------------------

What am I doing wrong here? I think I'm having an unnecessairly hard
time solving this, so please show me if there's an easier way.

Writing all this also leads me to a second question:

Why does DTML require that I explicitly look-up names-space elements
in the special namespace variable (_)?  Couldn't many of these
expressions be rewritten with more clarity as something like (<!--#var
"doc.id"-->)?  What does this special _ object buy me?

Thanks for your help.

Dave

-- 
David J. C. Beach
<beach@verinet.com>