[ZPT] Repeat over dict with options

David Pratt fairwinds at eastlink.ca
Thu Jun 3 09:37:08 EDT 2004


Hi Chris:

This is what I am using for the output that will work fine in the short 
term ( I'll likely use divs in the end as opposed going with a table)   
  I will only be returning the dictionary from the script if there are 
results, otherwise script will return a message indicating no records 
found.  Thanks Chris :)

Regards,
Dave

     <tal:x repeat="key options/results/keys">
     <table tal:define="value options/results;
                                      v python:value[key]">
        <tr>
           <td><strong>Foo:</strong></td>
           <td tal:content="v/foo">
           value of foo
           </td>
        </tr>
        <tr>
           <td><strong>Foo2:</strong></td>
           <td tal:content="v/foo2">
           value of foo2
           </td>
        </tr>
     </table>
     <br/>
     </tal:x>

On Thursday, June 3, 2004, at 04:35 AM, Chris Withers wrote:

> 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