Adding ZPT in __init__ method
Hello, I want to add a ZPT at initialization (in the __init__ method) of my folderish product. Why can't I just use: self.manage_addPageTemplate(id='ZPTid',title='title',text='content') Can someone give me the right syntax to do this? I've tried the following, but aq_parent doesn't exists at initialization of your product (thanks Casey): parent = getattr(self, 'aq_parent', None) self._createZPT(parent, 'ZPTidentity', 'title', 'Template') def _createZPT(self, parent, id, title, content): """Add a PageTemplate to the News product""" parent._setObject(id, ZopePageTemplate.ZopePageTemplate(id, text=content)) getattr(parent, id).pt_setTitle(title) Greetz Nico
Nico de Boer wrote:
Hello,
I want to add a ZPT at initialization (in the __init__ method) of my folderish product. Why can't I just use:
self.manage_addPageTemplate(id='ZPTid',title='title',text='content')
I don't know if it is the best solution, but you can define a method manage_afterAdd(self,item,container) and add the page template there (remember to call the ancestors' manage_afterAdd if needed, multiple inheritance can be messy). Bye -- Luca Olivetti Wetron Automatización S.A. http://www.wetron.es/ Tel. +34 93 5883004 Fax +34 93 5883007
Nico de Boer wrote:
Hello,
I want to add a ZPT at initialization (in the __init__ method) of my folderish product. Why can't I just use:
self.manage_addPageTemplate(id='ZPTid',title='title',text='content')
Are you sure youre not looking for PageTemplateFile, which behaves like DTMLFile or HTMLFile? cheers, Chris
On Friday, May 31, 2002, at 06:00 PM, Nico de Boer wrote:
add a ZPT at initialization (in the __init__ method) of my folderish product. Why can't I just use:
self.manage_addPageTemplate(id='ZPTid',title='title',text='content')
Can someone give me the right syntax to do this?
Firstly, you need to do it in a manage_afterAdd(self,item,container) method: def manage_afterAdd(self,item,container): ''' Add a PageTemplate customizable by the site manager ''' self.manage_addProduct['PageTemplates'].manage_addPageTemplate( 'myid',text=open(filepath).read() ) Having methods like 'manage_addDTMLMethod' available from every folder has been discouraged for quite a while due to collisions on this flat namespace. -- Stuart Bishop <zen@shangri-la.dropbear.id.au> http://shangri-la.dropbear.id.au/
participants (4)
-
Chris Withers -
Luca Olivetti -
Nico de Boer -
Stuart Bishop