TAL Question: Iterating through a list
All: I'm scratching my head trying to figure out how to to iterate over a list using TAL. Here's the scenario: I am calling a python script which wraps around a ZSQL method and simply returns the result set. The set comes back as a list of dictionaries. I'm getting stuck because I can't figure out how to tell TAL to to 1) grab each item and 2) grab the value associated with each dictionary key. On a related note is there a way to call a ZSQL method directly through page templates? Thanks in advance, -steve snesbitt@cobaltgroup.com
On a related note is there a way to call a ZSQL method directly through page templates?
Indeed, there is one. <select name="MySelection" size="1"> <option tal:repeat="Iteration container/MyZSQL" tal:content="Iteration/aName" tal:attributes="value Iteration/aValue"></option> </select> This example fills a Drop-Down-Box with something taken from th ZSQL-Method "MyZSQL". The ZSQL-Method has to deliver the fields "aName" and "aValue". The option-tag is repeated as often as there are results for myZSQL. Hope this is what you have been looking for. Thilo
I am calling a python script which wraps around a ZSQL method and simply returns the result set. The set comes back as a list of dictionaries. I'm getting stuck because I can't figure out how to tell TAL to to 1) grab each item and 2) grab the value associated with each dictionary key.
I'm scratching my head trying to figure out how to to iterate over a list using TAL. Here's the scenario:
Iterating over a list (coming from a script) is as usual: <span tal:repeat="element container/list_making_script"> <span tal:content="element/attribute">Value of some attribute of an element of a list</span> </span> Iterating over a dictionary's values is thus: <span tal:repeat="value context/dictionary/values"> <span tal:content="value">Value from a dictionary</span> </span> (Note that this is the usual Python method for getting the values of a dictionary. In Python, one would say dict.values() instead. You can also use dict.keys(), or with a little more work, dict.items() in the same manner.) So put 'em together: <span tal:repeat="dictionary container/list_making_script"> <span tal:repeat="value dictionary/values"> <span tal:content="value">Some value from a dictionary in a list</span> </span> </span> --jcc
participants (3)
-
J Cameron Cooper -
Nesbitt, Steve -
Thilo Rößler