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']]]

Becomes:

<ul>
 <li>a</li>
 <li>b</li>
 <ul>
  <li>c</li>
  <ul>
   <li>d</li>
   <li>e</li>
  </ul>
 </ul>
</ul>


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)
<ul>
 #for item in items
  #if isinstance(item, list)
   $make_list(item)
  #else
   <li>$item</li>
  #end if
 #end for
</ul>
#end def
$make_list(items)

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  /  [EMAIL PROTECTED]  /  http://blog.ianbicking.org
_______________________________________________
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt

Reply via email to