[Zope] Calling a ZPT on an object
Casey Duncan
casey@zope.com
Tue, 27 Aug 2002 09:19:34 -0400
On Tuesday 27 August 2002 08:45 am, Felix Ulrich-Oltean wrote:
> Hi
>=20
> I have made a python Product and I'm trying to set up its public
> view. The user can pick (per instance) which template to use from a
> folder-full of templates. I want the index_html method of my object
> to call the chosen template with the correct bindings, i.e. here
> should refer to my object instance.
>=20
> The templates are stored in the root of the site in a folder called
> "zest_templates/news", and my object has a property called "template"
> which is the id of one of the PT's in to folder. So, my attempt is
> below, but obviously it does not work, specifically, the "here" is not
> bound correctly.
>=20
> def index_html(self, REQUEST=3DNone):
> """Front-end view of the story."""
> return self.zest_templates.news[self.template](self, REQUEST)
> =20
> How can I do this?
Try:
pt =3D self.zest_template.news[self.template].__of__(self)
return pt()
The key is the __of__ method which makes the template an acquisition wrap=
per=20
around your product instance.
hth,
-Casey