[Zope] Returning lists from python back to dtml

douwe@oberon.nl douwe@oberon.nl
Thu, 25 Jul 2002 16:11:27 +0200

> Hi,
> I must admit I'm relatively new to both python and Zope but have a problem
> which I can't find the solution to in the (easy-to-reach)
> documentation.  A
> lot has been written about passing data from dtml to python
> scripts, but not
> much in the other direction.
> I have no problems returning simple lists, e.g.
> # getResults
> return (1,2,3,4,5)
> ...where the results are returned to a dtml method using something like:
> <dtml-in "getResults()">
>    <dtml-var sequence-item>
>    </dtml-in>
> However, I wish to pass a table of results with 'column names'
> (in layman's
> terms), such that I can read the returned results something like...
> <dtml-in "getResults()">
>    <dtml-var Column1> <dtml-var Column2> <dtml-var Column3>
>    </dtml-in>
> So, how do I pass named results from python script to dtml?
> Thanks for your thoughts.


Am I right when I say that you actually want to return a list of
dictionaries (tag value pairs)? In that case you should return
something like:
def getResults():
    return [ { 'Column2':'foo1', 'Column3','bar1'}, { 'Column2':'foo2',
'Column3','bar2'} ]

although I suppose you need an extra <dtml-with sequence_item> (I'm not very
much into DTML)

Hope this helps you in any way,