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

DA Loeffler David.Loeffler@bristol.ac.uk
Wed, 11 Sep 2002 13:33:02 +0100 (BST)


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