[Zope] Rules on passing variables from dmtl-python-dtml

McDonnell, Larry lmcdonnell@protonenergy.com
Wed, 11 Sep 2002 12:06:40 -0400


Thanks this was a big help. I know in the future I'll need to do more
scripting.

-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of DA
Loeffler
Sent: Wednesday, September 11, 2002 8:33 AM
To: McDonnell, Larry
Cc: 'Zope@Zope. Org' (E-mail)
Subject: Re: [Zope] Rules on passing variables from dmtl-python-dtml




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


_______________________________________________
Zope maillist  -  Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )