[Zope] Seeing a DTML-LET from a Python Script?

Thomas B. Passin tpassin@mitretek.org
Thu, 28 Feb 2002 11:30:36 -0500


[Jean Jordaan]
>
> Quick question: if I do this:
>
>   <dtml-let somevariable="'whatever'">
>   <dtml-var pythonScript>
>   </dtml-let>
>
> how do I get at the value of somevariable in pythonScript? I'd assume
> by binding the namespace _ and doing _['something'] but that raises a
> key-error ..
>
> The nearest info I could find on this in a websearch is:
> http://www.zope-forum.org/forum/viewthread.php?FID=24&TID=519
> but I couldn't quite figure that out ..
>

The easiest way is the same way you would use to send a named parameter to a
dtml method.

Say your Python script is called "py_1", and it expects a parameter named
"theVar".  Here is what you can do:

<dtml-let p1=" 'This is a test' ">
   <dtml-var "py_1(theVar=p1)">
</dtml-let>

Note that I have added two spaces in the value of p1 so you can see the
difference between double and single quotes.  Of course, the value of p1
does not have to be a string;  if your script accepts a number, you can
write:

<dtml-let p1="4">
   <dtml-var "py_1(theVar=p1)">
</dtml-let>

Cheers,

Tom P