[Zope] python variables rendered by dtml

J Cameron Cooper jccooper@jcameroncooper.com
Wed, 05 Mar 2003 00:49:20 -0600


>
>
>>It doesn't need to be named. Call your python script via the dtml-in,
>>    
>>
>return
>  
>
>>foo, and all will be well. I do it all the time.
>>    
>>
>
>But what I want to do is the opposite:
>
>to call the dtml-method from the python script with the list as an argument.
>  
>
In order to render the content in the script? I'll trust that you really 
need to do this and stow the alternatives:

you have a list-like result set you got from

foo = container.someSql()

you have a DTMLMethod 'renderSql' that says

<dtml-in someResultList>
  <dtml-var someField> ...
</dtml-in>

In your PythonScript you can just do

return context.renderSql(someResultList=foo)

to render it with foo in the namespace as someResultList. But that'll 
leave everything else out of the namespace, so you really want to do

return context.renderSql(client=context, someResultList=foo)

if you want to aquire anything from your surroundings (which you almost 
always want to do.)

Canonically, or if you want to use you REQUEST namespace or manipulate 
your RESPONSE in your DTML method, you can say

request = container.REQUEST
response =  request.RESPONSE
return context.renderSQL(client=context, REQUEST=request, 
RESPONSE=response, someResultList=foo)

                --jcc
        (not canonical)