dtml-with question
Hi, I have a DTML-method that picks up a dictionary from an External Method, and should create a folder and a page template within it, but it doesn't work correctly: <dtml-let dictionaryvar="filescript(REQUEST)"> <dtml-let mytitle="dictionaryvar['title']" body="dictionaryvar['body']" myid="dictionaryvar['fid']" > <dtml-call "manage_addFolder(myid, mytitle)"> <dtml-with myid> <dtml-call "manage_addProduct['PageTemplates'].manage_addPageTemplate('index_html', mytitle, body)"> </dtml-with> </dtml-let> </dtml-let> This creates a folder alright but creates the PT at the same level and not inside it. However if I try replacing myid in the manage add line with 'test' and do a <dtml-with test> it works just great. Any pointers anyone? TIA Marie Robichon Web Task Force European Synchrotron Radiation Facility BP 220 38043 Grenoble Cedex France http://www.esrf.fr Tel: (33) 04 76 88 21 86 Fax: (33) 04 76 88 24 27
Marie Robichon wrote:
Hi,
I have a DTML-method that picks up a dictionary from an External Method, and should create a folder and a page template within it, but it doesn't work correctly:
<dtml-let dictionaryvar="filescript(REQUEST)">
<dtml-let mytitle="dictionaryvar['title']" body="dictionaryvar['body']" myid="dictionaryvar['fid']" >
<dtml-call "manage_addFolder(myid, mytitle)">
<dtml-with myid>
<dtml-call "manage_addProduct['PageTemplates'].manage_addPageTemplate('index_html', mytitle, body)"> </dtml-with> </dtml-let> </dtml-let>
This creates a folder alright but creates the PT at the same level and not inside it.
However if I try replacing myid in the manage add line with 'test' and do a <dtml-with test> it works just great. Any pointers anyone?
TIA Marie Robichon
hi, your error is in the dtml-with... myid is a string and not an object:
<dtml-call "manage_addFolder(myid, mytitle)">
<dtml-with myid>
so try something like this to get the object with id=myid: <dtml-with "_.getattr(this(),myid)"> -maik
hi,
your error is in the dtml-with... myid is a string and not an object:
<dtml-call "manage_addFolder(myid, mytitle)">
<dtml-with myid>
so try something like this to get the object with id=myid:
<dtml-with "_.getattr(this(),myid)">
-maik
Thanks but I seem to be getting an attribute error __getslice__ when I try to do this: <dtml-let dictionaryvar="filescript(REQUEST)"> <dtml-if "not dictionaryvar.has_key('file')"> <dtml-call "RESPONSE.redirect('fileform?nofile=1')"> <dtml-else> <dtml-let mytitle="dictionaryvar['title']" body="dictionaryvar['body']" myid="dictionaryvar['fid']" > <dtml-with "ContentHolder.createInObjectManager(myid,REQUEST)"> <dtml-call "propertysheets.general.manage_changeProperties(title=mytitle)"> <dtml-with "_.getattr(this(),myid)"> <dtml-call "manage_addProduct['PageTemplates'].manage_addPageTemplate('contents_html', mytitle, body)"> <dtml-call "manage_addFolder('img','my images')"> </dtml-with> </dtml-with> </dtml-let> </dtml-if> </dtml-let> and following Chris Withers advice and using a python script: theDict = context.filescript(context.REQUEST) mytitle = theDict['title'] body = theDict['body'] myid = theDict['fid'] dispatcher = context.manage_addProduct['ContentHolder'] dispatcher.manage_addContentHolder(myid,mytitle) myproduct=context[myid] myproduct.manage_addProduct['PageTemplates'].manage_addPageTemplate('index_html',mytitle,body) I get an attribute error Error Type: AttributeError Error Value: manage_addContentHolder I know that it would be better to do a product that using zclasses and that is our next step but I would like to be able to get this working before I tackle that big step... TIA Marie
Hi Marie, You _really_ should be using Python Scripts for this kind of thing. Still, good to see you're using ZPT :-) Anyway, here's the Python script that will do what you want: theDict = context.filescript(context.REQUEST) mytitle = theDict['title'] body = theDict['body'] myid = theDict['fid'] context.manage_addFolder(myid,mytitle) myfolder = context[myid] myfolder.manage_addProduct['PageTemplates'].manage_addPageTemplate('index_html',mytitle,body) return 'Done' cheers, Chris
participants (3)
-
Chris Withers -
Maik Jablonski -
Marie Robichon