[ZPT] Recursive structures

Ian Bicking ianb at colorstudy.com
Fri Jul 1 16:42:11 EDT 2005

I'm surprised this has never come up for me before, but now I want to 
render a recursive data structure and I'm at a loss how I might do that 
in ZPT.  Or, what the best workaround would be.  E.g.:

['a', 'b', ['c', ['d', 'e']]]



I guess the template could call itself repeatedly.  Which means the list 
can't be embedded in any other markup.  Hrm... in Cheetah I'd do:

#def make_list(items)
  #for item in items
   #if isinstance(item, list)
   #end if
  #end for
#end def

It's a code-heavy template, and maybe it should just be written in 
Python, but it's also reasonable to allow people to add classes to 
items, further logic, etc.

Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org

More information about the ZPT mailing list