[Zope] dtml-let and python script

Luca Manini manini@flashnet.it
Sat, 11 May 2002 10:01:27 +0200


Kevin Lewandowski writes:

 > > Maybe this is really easy but I can find an example anywhere.
 > > How can I access a variable set with "dtml-let" inside of a
 > > python script?
 > > 
 > > For example:
 > > 
 > > <dtml-let val="'a value'">
 > >   <dtml-var python_script>
 > > </dtml-let>
 > > 
 > > How can I access val from inside python_script?

One (the?) solution is to pass the 'under' namespaceto the script,
that is to specify _ as the value of 'bind namespace' in the Python
Script. The you have access to that namespace where (I think) the
variable val has been 'pushed'. To get the var out of it you can:

1) specify val as parameter and use it 'normally'

## Script (Python) "script"
##bind container=container
##bind context=context
##bind namespace=_
##bind script=script
##bind subpath=traverse_subpath
##parameters=val
##title=
##
return 'script - ' + str(val)

2) do not specify it as parameters and get it explicitly from the namespace

## Script (Python) "script"
##bind container=container
##bind context=context
##bind namespace=_
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
return 'script - ' + str(val)


Not really sure about the 'theory', but it works in practice. 

	bye, Luca