[ZPT] How to create page template with python script

Clemens Robbenhaar zpt@zope.org
Fri, 14 Mar 2003 00:00:53 +0100


David Chandek-Stark writes:
 > I am trying to write a script that creates a custom folder object and then
 > creates a page template in that folder. I have the folder creation part
 > working (mostly):
 > 
 > ###################################
 > """
 > Create project folder from form data
 > """
 > 
 > # assign value to id
 > id=field_project_id
 > 
 > # create the folder
 > context.manage_addProduct['OFSP'].manage_addFolder(id,
 > title=field_project_title)
 > 
 > # add project properties
 > doc=getattr(context, id)

... and adding a page template works (nearly) the same:

 doc.manage_addProduct['PageTemplates'].manage_addPageTemplate(
            pt_id, text=text)
 pt=getattr(doc, pt_id)

where "pt_id" is the id of the page template and "text" is the
raw text of the page template.

The code is untested cut & paste from some other product.

Anyway I hope it helps (or even works ;-)
Clemens