[ZPT] tal:repeat over the sorted keys of a dictionary
Dieter Maurer
dieter at handshake.de
Fri Jul 25 22:44:03 EDT 2003
Jean Jordaan wrote at 2003-7-25 11:46 +0200:
> .. the subject says it all. I want to do something like:
>
> <ul tal:define="keys licenses/keys; sortedkeys keys/sort"
> tal:repeat="key sortedkeys">
> <li tal:content="python:licenses[key]" />
> </ul>
>
> Unfortunately, "keys/sort" (and "python:keys.sort()") return None.
> What am I missing?
An intermediate "dummy" assignment:
<... tal:define="
keys licenses/keys;
dummy keys/sort;
"
tal:repeat="key keys"
...
>
The "keys/sort" sorts "keys" as a side effect.
I do not say that side effects in templates are easy to understand.
Dieter
More information about the ZPT
mailing list