Am Montag, den 24.01.2005, 00:20 +0800 schrieb Hong Yaun:
Paul Winkler wrote:
a trivial example:
# this is Products/MyFunctions/__init__.py
from AccessControl import ModuleSecurityInfo
def trivialFunc(): return True
def anotherFunc(): return False
ModuleSecurityInfo('Products.MyFunctions').declarePublic( 'trivialFunc', 'anotherFunc' )
# EOF
Thanks for the sample and now I can access trivialFunc() from within a template file using:
<p tal:content="python:modules['Products.MyFunctions'].trivialFunc()"></p>
It works fine, just somewhat cumbersome. One way to simplify its usage is to use tal:define, like:
<p tal:define="func python:modules['Products.MyFunctions'].trivialFunc" tal:content="func()"></p>
But this would require using tal:define in every template file that could access the function.
Is there any other way to simplify the access to the function?
Yes, simply dont write application code in pagetemplates :-) You can either stuff your complete API in context by defining useful classes and methods or do the support scripting in one or some python scripts. Regards Tino