[ZPT] tal:repeat over the sorted keys of a dictionary
Shane Hathaway
shane at zope.com
Fri Jul 25 12:56:46 EDT 2003
Jean Jordaan wrote:
>> <ul tal:repeat="key licenses/keys/format:sort">
>> <li tal:content="licenses/key" />
>> </ul>
>
>
> OK, then 'format' is a script that takes the output of 'keys', passes it
> to 'sort', and returns the result? If it's ubiquitous, fine ..
> otherwise, I like the 'dummy' route sans helper scripts more.
No. "format:" is a namespace qualifier that tells ZPT to call a script
in the standard formats module rather than look for an attribute or
item. Not all namespaces imply a module import, though. Each namespace
has a different meaning. This mechanism is intended to be ubiquitous.
> Is '<li tal:content="licenses/key" />' a feature deriving from the
> proposed changes? As is, it raises a KeyError on 'key'.
Oops, silly me. Let me fix the bugs I introduced. :-)
<ul tal:repeat="key licenses/call:keys/format:sorted">
<li tal:content="licenses/key:?key" />
</ul>
Yikes, that second expression is looking ugly. Therefore, I would
revert it to a Python expression:
<ul tal:repeat="key licenses/call:keys/format:sorted">
<li tal:content="python: licenses[key]" />
</ul>
This is OK, but here's an alternative that would work if we added one
more function to the standard formats module:
<ul tal:repeat="item licenses/format:sorted_dict_items">
<li tal:content="item/value" />
</ul>
Shane
More information about the ZPT
mailing list