[Zope] Using external python functions from TAL

Dieter Maurer dieter@handshake.de
Fri, 6 Jun 2003 20:55:11 +0200


Sean Hastings wrote at 2003-6-5 13:34 -0400:
 > ...
 > I have been playing around with TAL, and external python products. I have no
 > problem calling external python methods on an object using the root
 > namespace variable "here". as in :
 > 
 > <td tal:content="python:here.foo("></td>
 > 
 > or on some other object that I find through that root. as in:
 > 
 > <tr tal:repeat="object python:here.getObhectsList()">
 > 	<td tal:content="python:object.foo"></td>
 > </tr>
 > 
 > But I have no idea how to access a random function that is not an object
 > method.
 > 
 > For example, I would like to be able to have a module called
 > MyProduct.Functions, containing a function foo(), and call it like this:
 > 
 > <td tal:content="python:MyProduct.Functions.foo()"></td>

I am not sure, I understand your problem fully.

The namespace of External Methods is somehow flat.
There are no modules of External Methods.

However, you can collect and organized External Methods in
Zope "Folder" objects. Suppose, you have a "Folder"
"MyFunctions" which contains the External Method "Function",
then you can access it as:

     <td tal:content="python: here.MyFunctions.Function()">


The magical passing of "self" will probably no longer give
the expected result. You will probably need to pass "self"
explicitely (when your External Method needs this "self").
This would look somehow like:

     <td tal:content="python: here.MyFunctions.Function(here,...)">


The access chain to your External Method can be arbitrary long.


Dieter