Rules on passing variables from dmtl-python-dtml
Hi, I need to understand the rules in passing variables between dtml and python. All I am doing at this point is converting an integer to a string. In this format when I test it I get the results I was looking for. Bound Names context, container, script, traverse_subpath # Example code: # Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE y='0'+str(x) return y But I'm lost on the passing. <dtml-call "int_to_string(num)"> **<dtml-var y>** Any pointer would be a great help, thanks. Larry McDonnell Proton Energy Systems 50 Inwood Rd. Rocky Hill, CT 06067 (860) 571-6533 ext. 531 Email:lmcdonnell@protonenergy.com www.protonenergy.com
On Wed, 11 Sep 2002, McDonnell, Larry wrote:
<dtml-call "int_to_string(num)">
**<dtml-var y>**
y is a local variable in the script. Its scope does not extend to the calling DTML method. The script returns the value of y, and then the DTML does nothing with it - it doesn't tie it to a local variable name, so the variable no longer has a name (technical term: it has zero reference count) and it is cleaned up by the Python garbage collector. Hence, either give it a name in the DTML method's namespace: <dtml-let y="int_to_string(num)"> <dtml-var y> </dtml-let> or, if you just want to use the variable once, use it as soon as you get it: <dtml-var "int_to_string(num)"> Alternatively, amend your script to: request.set('y',y) instead of the return statement, and then y will be accessible within the DTML method, and anywhere else called in the processing of that Zope request. David
participants (2)
-
DA Loeffler -
McDonnell, Larry