[Zope] Rendering PageTemplateFile
Max M
maxm@mxm.dk
Tue, 24 Jun 2003 15:06:13 +0200
Jens Dobberthin wrote:
> ...(the last mail was in the wrong thread)...
>
> Salut,
>
> is there any way to render a page template file that is located on the
> hard disk?
>
> Code excerpt in a product:
>
> def foo(self):
> pt = PageTemplateFile('show.zpt', _prefix=skins_prefix)
> print pt # prints <PageTemplateFile at 0x89c5000>
> return pt() # --> error
>
> There is nothing wrong with the page template (actually it doesn't
> contain
> any tals just plain text). (The idea behind this is that I want to
> decide which
> template to show. So the skins_prefix may change.)
You need to give it some context.
def foo(self):
pt = PageTemplateFile('show.zpt', _prefix=skins_prefix)
return pt(self, self.REQUEST)
Alternatively you could also use PageTemplate()
def foo(self):
pt = PageTemplate()
pt.write('some zpt code, perhaps from a file.')
return pt(self, self.REQUEST)
Botha approached make you compile the zpt code every time, which is
expensive. It's better to store these templates in the zodb.
It is possible to dynamically select the template via a Python Script in
zpt. Your approach seems wrong!
regards Max M