[ZPT] sequence unpacking syntax in TAL

Fred L. Drake, Jr. fred at zope.com
Fri Jul 11 16:42:41 EDT 2003


This is a proposal to extend TAL to support sequence unpacking for the
tal:define and tal:repeat attributes.

The additional syntax would allow setting multiple values from a
single expression:

  <div tal:define=
       "userid, host  python:context.email_address.split('@', 1)"
       >

If context.email_address has the value 'jim at zope.com', this would set
the TAL variable userid to 'jim' and host to be set to 'zope.com'.
This could also be used to decompose more interesting values from
database queries or other sources.

By extension, this should be useful with tal:repeat loops as well:

  <tr tal:repeat=
       "userid, name, email, favcolor  context/user_info"
       >
    <td tal:content="userid"> user id </td>
    <td><a href="mailto:address"
           tal:attributes="href string:mailto:$email"
           tal:content="name"> user name </a></td>
    <td>Favorite color:
        <span tal:replace="favcolor"> color name </span> </td>
  </tr>

Does this seem generally useful to everyone?  Comments and suggestions
are welcome (as are patches!).


  -Fred

-- 
Fred L. Drake, Jr.  <fred at zope.com>
PythonLabs at Zope Corporation



More information about the ZPT mailing list