[Zope] Acquiring functions in ZPT

Richard Wesley hawkfish@electricfish.com
Tue, 22 Oct 2002 07:53:01 -0700


I have been puzzling over how to apply Python scripts to various 
kinds of things in a page template.  A simple example is a script I 
have called formatContactName that takes a name record and formats it 
as "last, first middle title suffix".  In a page template this would 
get used like so:

<span tal:content="object/formatContactName">placeholder</span>

It appears that I can only do this for a very limited class of 
objects:  It works fine for records obtained from a database query in 
the template itself, but it does _not_ work for a dictionary obtained 
from a SESSION variable or from the options parameter.

Nor does it work for a page template.  I currently use a table 
display macro for displaying database queries and I am having to pass 
in a list of column specifications via the options parameter which 
means that I am keeping display information in the form's Python 
script (bad design).  My tentative solution was to add list 
properties (describing the columns) to the page and then write a 
script to turn the list of column descriptor fields into a list of 
rows of single column descriptions.  I wrote the script (list_columns 
) and tried to call it as above:

<... tal:define="list_columns template/list_columns"...>

and again I got a name resolution problem.

This is a very handy facility, and I would like to make more use of 
it (writing methods like this to expand simple dictionaries is very 
appealing) but it seems to be mostly unavailable.

TIA,
Sincerely,

Richard Wesley
Co-President, Electric Fish, Inc.
<http://www.electricfish.com/>
(v) +1-206-493-1690x210
(f) +1-206-493-1697