[ZPT] Repeat over dict with options

Chris Withers chris at simplistix.co.uk
Thu Jun 3 03:35:15 EDT 2004


Hi David,

David Pratt wrote:

> In my zpt, I have done this:
> 
>    <span tal:define="value options/results">
>       <p>
>          <span tal:content="value">value of results</span>
>       </p>
>     </span>
> 
> which  yields:
> 
> {1:{'foo':'bar','foo2':'bar2'}, 2:{'foo':'barnone','foo2':'barnone2'}
> 
> I was expecting to get each item of the dictionary returned on a 
> separate line 

Why were you expecting that?! ZPT does no "magic"...

> My quest is how to get the values for foo and foo2 out of this so that 
> the result is

Here ya go:

<tal:x repeat="key options/results/keys">
<p tal:define="resultSet options/results/?key"
    tal:repeat="value resultSet/values"
    tal:content="value">
Dummy content
</p>
</tal:x>

...although I suspect you'll want something else before long, like the 1,2 and 
foo, foo2 ;-)

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk




More information about the ZPT mailing list