Seeing a DTML-LET from a Python Script?
Hi all 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 .. TIA, -- Jean Jordaan Upfront Systems http://www.upfrontsystems.co.za
On Thu, 28 Feb 2002, Jean Jordaan wrote:
Hi all
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 ..
DTMLDocument in: <dtml-let myvar="'hi'"> <dtml-var out> </dtml-let> PythonScript out: return _['myvar'] Bind _ to the namespace for the script. Works fine for me, Zope 2.5.0. Not sure why it wouldn't for you. -- Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Independent Knowledge Management Consultant
From: "Jean Jordaan" <jean@upfrontsystems.co.za>
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 ..
I''m not sure, but maybe it's accessible as context.somevariable? If not you could pass it to the pythonscript: <dtml-var "pythonscript(somevariable)"> Thats a cleaner and better way to do it anyway.
Hi Lennart, Joel Lennart:
I'm not sure, but maybe it's accessible as context.somevariable?
That would be great, but hasattr(context, 'somevariable') doesn't help ..
If not you could pass it to the pythonscript: <dtml-var "pythonscript(somevariable)"> Thats a cleaner and better way to do it anyway.
I can't .. I'm one step away from the calling method. This is what I'm trying to do: caller: <dtml-let control="control_name"> <dtml-var "dtmlmethod(this(), _)"> </dtml-let> dtmlmethod: <dtml-let state="pythonscript(param, param, ..)"> ... </dtml-let> pythonscript: return _['control'] This does not work. I've found that, in this simple case, it works if I do this: <dtml-let state=pythonscript> and this also works: <dtml-let state="pythonscript(_)"> if _ is defined as a parameter in pythonscript. I need to pass parameters, and I'd rather not need to pass a "magic" _ as first parameter .. -- Jean Jordaan Upfront Systems http://www.upfrontsystems.co.za
[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
participants (4)
-
Jean Jordaan -
Joel Burton -
Lennart Regebro -
Thomas B. Passin