[ZPT] Adding a ZPT programmaticly

Evan Simpson evan@digicool.com
Thu, 21 Jun 2001 10:27:44 -0400


Peter Bengtsson wrote:

> It took me some time to realize that you can't just use
> manage_addPageTemplate with ZPT to do what
> manage_addDTMLDocument('id','title',"""<dtml-var showpage>""") does.


You mean, it doesn't do it in one step?

>     def _createZPT(self, parent, id, title, content):
>         parent._setObject(id, ZopePageTemplate.ZopePageTemplate(id,
> text=content))
>         getattr(parent, id).pt_setTitle(title)

I don't know if you'd consider this easier, but you should be able to:

manage_addPageTemplate(id)

and then:

ob = parent[id]
ob.pt_setTitle(title)
ob.write(content)

Of course, it wouldn't be hard to add optional title and text arguments 
to manage_addPageTemplate.

Cheers,

Evan @ digicool