Passing parameters into DTML methods
I have the following dtml code piece (using Zope 1.10.2): <!--#call "updateValue(newval=100)"--> updateValue is a dtml method which looks like: <!--#if "hasProperty('lastValue')"--> <!--#call "manage_changeProperties(lastValue=newval)"--> <!--#else--> <!--#call "manage_addProperty('lastValue',newval,getPropertyType('default'))"--> <!--#/if--> When I view the dtml method, foo, with the call <!--#call "updateValue(newval=100)"--> I get the error below . Interestingly, if I change the method above to: <!--#if "hasProperty('lastValue')"--> <!--#call "manage_changeProperties(lastValue=100)"--> <!--#else--> <!--#call "manage_addProperty('lastValue',100,getPropertyType('default'))"--> <!--#/if--> And call it as <!--#call updateValue--> it works.... Is this the right way to pass in a parameter to a dtml method? Traceback (innermost last): File lib/python/ZPublisher/Publish.py, line 877, in publish_module File lib/python/ZPublisher/Publish.py, line 590, in publish (Info: /SeisRes/SeisResSub/ST295/Exp-2-18-99/SeisMod/submission/variables/submithost/foo) File lib/python/OFS/DTMLMethod.py, line 155, in __call__ (Object: foo) File lib/python/OFS/DTMLMethod.py, line 151, in __call__ (Object: foo) File lib/python/DocumentTemplate/DT_String.py, line 513, in __call__ (Object: foo) File lib/python/DocumentTemplate/DT_Util.py, line 266, in eval (Object: updateValue(newval=100)) File <string>, line 0, in ? File lib/python/OFS/DTMLMethod.py, line 147, in __call__ (Object: updateValue) File lib/python/DocumentTemplate/DT_String.py, line 513, in __call__ (Object: updateValue) File lib/python/DocumentTemplate/DT_Util.py, line 266, in eval (Object: hasProperty('lastValue')) File <string>, line 0, in ? NameError: (see above) Regards, Albert Boulanger aboulanger@ldeo.columbia.edu
Try: <!--#call "updateValue(_.None,_,newval=100)"--> The problem is that when you call a DocumentTemplate without parameters, the system sees it's a DocumentTemplate and passes through the current namespace. If you call it with parameters, the system in effect assumes you know what you're doing and doesn't mess with the parameters you're passing. Normally, DocumentTemplates take two positional arguments before the keyword arguments - specifically, a 'client' and a 'namespace'. '_' is the current DTML namespace, that's why it's passed in second. _.None as the first parameter skips over the 'client' parameter, which isn't needed. At 07:47 PM 6/28/99 -0500, Albert Boulanger wrote:
I have the following dtml code piece (using Zope 1.10.2):
<!--#call "updateValue(newval=100)"-->
updateValue is a dtml method which looks like:
<!--#if "hasProperty('lastValue')"--> <!--#call "manage_changeProperties(lastValue=newval)"--> <!--#else--> <!--#call "manage_addProperty('lastValue',newval,getPropertyType('default'))"--> <!--#/if-->
When I view the dtml method, foo, with the call <!--#call "updateValue(newval=100)"--> I get the error below . Interestingly, if I change the method above to:
participants (2)
-
Albert Boulanger -
Phillip J. Eby