[ZPT] PageTemplateFile and other methods
Evan Simpson
evan@digicool.com
Tue, 10 Jul 2001 11:58:27 -0400
Peter Bengtsson wrote:
> [not sure if this is only a ZPT question, but I start here]
>
> my python product starts like this:
>
> def somemethod():
> return ('a','b')
>
> from Products.PageTemplates.PageTemplateFile import PageTemplateFile
> manage_addNetSendForm = PageTemplateFile('netsendform', globals())
>
> Then there's the file netsendform.zpt in which I try to get access to
> somemethod() but can't.
> I have tried <div tal:define="res here/somemethod">
> and container and options and modules (security problems).
Tricky one. Your Product's module is not accessible through any of the
builtin template names, except indirectly through "modules". You
*could* stuff the function directly into the Template, by saying:
manage_addNetSendForm.somemethod = somemethod
If you want to provide several addition methods to the Template, you
would probably be better off subclassing:
class ThisPageTemplate(PageTemplateFile):
def method1(self):
pass
#etc.
manage_addNetSendForm = ThisPageTemplate('netsendform', globals())
In either case, you would need to add security declarations, like so (in
the class body):
from AccessControl import ClassSecurityInfo
security = ClassSecurityInfo()
security.declareProtected('View', 'method1')
Finally, you will access the method using the "template" variable, as in
"tal:define="foo template/method1".
Cheers,
Evan @ digicool