Ian Bicking wrote:
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.:
I think it should *definitely* be written in Python, although a "Script
(Python)" should suffice. Add a "Script (Python)" with an ID of
"make_list" and a parameter list of "items" The following is untested,
but should work, I think. Beware of any special text in the strings
['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:
#for item in items
#if isinstance(item, list)
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.
text = "<ul>\n"
for item in items:
if isinstance( item, ( list, tuple )):
text += context.make_list( item )
text += "<li>" + str(item) + "</li>\n"
return text + "</ul>"
Zope maillist - Zope@zope.org
** No cross posts or HTML encoding! **
(Related lists -