[Zope-dev] Re: TALES idea: tuple unpacking

Shane Hathaway shane@zope.com
Wed, 23 Jul 2003 10:00:37 -0400


Philipp von Weitershausen wrote:
> I agree that it is 'yucky', but I have to disagree with your proposed
> solution. I would rather suggest making TALES aware of integer indexes
> for sequences. Example::
> 
>   <tal:block repeat="user_files here/listFilesByUser">
>     User: <tal:dummy replace="user_files/0" />
>     File: <tal:dummy replace="user_files/1" />
>   </tal:block>

Here's the way I'd like to spell it:

   <div tal:repeat="user_files here/listFilesByUser">
     User: <span tal:replace="user_files/int:0" />
     File: <span tal:replace="user_files/int:1" />
   </div>

Literally, "user_files/int:0" says "get item 0 of user_files, 
interpreting '0' as an integer".  Technically, this could be interpreted 
as "get the attribute named 0 or item 0", but an attribute name must be 
a string, so implicitly it really just says "get item 0".

We've come up with a number of generally useful prefixes, BTW.  Off the 
top of my head:

call:   -- Call a named method
int:    -- Look up an item by index
format: -- Perform simple formatting operations like "format:money"
zope:   -- Access a big Zope API

It sure would be nice to have these prefixes, both in Zope 2 and Zope 3.

Shane