[Zope3-Users] Calling PageTemplate in Content object
Tom Dossis
td at yoma.com.au
Wed May 24 16:50:13 EDT 2006
David Johnson wrote:
> I'm trying to call a page template in a content object, but nothing
> seems to happen. No exceptions, no output, and no errors. I figure I'm
> missing something. Anyone have ideas?
>
> ...
> from zope.pagetemplate.pagetemplatefile import PageTemplateFile
>
> class OrderView:
>
> def city(self):
> return 'Fort Worth'
>
> class ProcessStep(StepFactory):
>
> implements(IProcessStep)
>
> orderform = PageTemplateFile('orderform.pt')
>
> def message(self,request):
> return self.orderform(self,order=OrderView())
>
> ...
> orderform.pt
> ...
> <html>
> <body>
> My City Is:
> <div tal:replace="order/city"/>
> </body>
> </html>
>
> ...
>>>> step.message(request)
>>>>
> *** Note how nothing is returned - no exceptions and no output.
Have a look at zope/pagetemplate/readme.txt - it shows (one way) how to
inject 'order' into the tal 'namespace'., e.g.
>>> class MyPageTemplateFile(PageTemplateFile):
... def pt_getContext(self, args=(), options={}, **kw):
... rval = PageTemplateFile.pt_getContext(self, args=args)
... options.update(rval)
... return options
>>> orderform=MyPageTemplateFile('orderform.pt')
>>> orderform(order=OrderView())
More information about the Zope3-users
mailing list