[Zope] while-loops; was: help

Clemens Robbenhaar robbenhaar@espresto.com
Fri, 1 Nov 2002 18:21:31 +0100


 > Reichman, Tal (NIH/NCI) wrote:
 > > I am a newbie so I must appoligize for my current lack of knowledge.
 > > Can I create a while loop in a template...

 I guess the problem is how to program a "while" loop in opposite to a
"for" loop, i.e. something where You don not know in advance how many
iterations it may take.

 The anwser is: it is not possible in a page template or DTML.
Use a Script (Python) instead. E.g.:

parent = context
parents = []
while parent.ap_parent:
  parents.append(parent.getId())
  parent = parent.aq_parent

return parents


then you can do something like

 <b tal:repeat="parent python:here.getParents()" tal:content="parents" />

to print all acquisition parent ids (in reverse order).
Warning: script is untested, may contain syntax errors and the like.

Cheers,
Clemens