Wrestling with the ZopeBook (ScriptingZope.stx), I'm trying to call a script from a DTML document to return eq the title for the document (as learning curve). The document has: <form action="myScript" method="POST> <input type="submit"> </form> The 'myScript' has: Return context.title The result is the title for the folder where the document is in. I'm expecting the title for the document itself. Context always seems to be the folder I'm working on. How do I get the object (document)? Wim
On Tue, May 13, 2003 at 05:08:42PM +0200, Wim Bekker wrote:
The 'myScript' has: Return context.title
The result is the title for the folder where the document is in. I'm expecting the title for the document itself.
Context always seems to be the folder I'm working on. How do I get the object (document)?
yes, context is the folder and not the DTML object. Go to the script's Bindings tab, bind something to "Namespace", and you should be able to access anything the DTML doc or method knows about that way. -- Paul Winkler home: http://www.slinkp.com "Muppet Labs, where the future is made - today!"
Wim Bekker wrote:
Wrestling with the ZopeBook (ScriptingZope.stx), I'm trying to call a script from a DTML document to return eq the title for the document (as learning curve).
The document has: <form action="myScript" method="POST> <input type="submit"> </form>
The 'myScript' has: Return context.title
The result is the title for the folder where the document is in. I'm expecting the title for the document itself.
Context always seems to be the folder I'm working on. How do I get the object (document)?
myScript is not called from within your dtml-method. In your example myScript is just a relative URL that triggers the execution of the script when the user presses the submit button. If I understand you (and zope) correctly, what you're trying to do is to discover from where myScript is called, and this has nothing to do with acquisition. You can find its URL looking at the REQUEST.HTTP_REFERER or easier, create a hidden input in your form: <form action="myScript" method="POST> <input type="hidden" name="caller_title" value="&dtml-title;"> <input type="submit"> </form> and add a caller_title parameter to myScript. Maybe zope provides some nice way to determine the object which has triggered the execution of myScript, I don't know ... REQUEST.HTTP_REFERER and some traversal method can take you to the object. HTH -- //// (@ @) ---------------------------oOO----(_)----OOo------------------------ Los pecados de los tres mundos desapareceran conmigo. Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain) --------------------------------------------------------------------
On Tue, May 13, 2003 at 06:59:58PM +0200, Alexis Roda wrote:
myScript is not called from within your dtml-method. In your example myScript is just a relative URL that triggers the execution of the script when the user presses the submit button.
oops, i missed that. of course he's right. --PW -- Paul Winkler home: http://www.slinkp.com "Muppet Labs, where the future is made - today!"
On Tuesday 13 May 2003 08:08 am, Wim Bekker wrote:
The document has: <form action="myScript" method="POST> <input type="submit"> </form>
The 'myScript' has: Return context.title
Context always seems to be the folder I'm working on. How do I get the object (document)?
By name, as in: context.myDocument The script is *not in* the document, it's in the same folder. DTML documents/methods are not container objects. I think you're confusing calling with containment (admittedly, DTML probably encourages this). If you want to pass objects to the script, you can also simply call it with arguments: <dtml-var expr="myScript(title)"> will pass it the document's title, for example. This is probably much better style, generally. Of course, just to really confuse yourself, you could pass the whole namespace: <dtml-var expr="myScript(_)"> Then your first argument will be a mapping containing all the names known to the document. HTH, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
On Tuesday 13 May 2003 10:33 am, Terry Hancock wrote:
Context always seems to be the folder I'm working on. How do I get the object (document)?
By name, as in: context.myDocument
The script is *not in* the document, it's in the same folder. DTML documents/methods are not container objects.
I think you're confusing calling with containment (admittedly, DTML probably encourages this).
My comments make sense if you'd actually called myScript from myDocument -- but as others have pointed out, your example doesn't do that -- the rendered form in the user's browser HTTP *posts* to myScript. Which is a whole 'nother thing. In that case, all your info will be accessed from the REQUEST. You need to read some examples on this in any of the intro Zope books. Or you might be able to find a howto. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
On Tue, 2003-05-13 at 08:08, Wim Bekker wrote:
Wrestling with the ZopeBook (ScriptingZope.stx), I'm trying to call a script from a DTML document to return eq the title for the document (as learning curve). [...] The 'myScript' has: Return context.title
The result is the title for the folder where the document is in. I'm expecting the title for the document itself.
You've got two problems. The first is that some objects acquire certain attributes from their container. A DTML Method will always return the names defined by its container before exposing its own names. The more fundamental problem, though, is that you aren't calling your form object when you think you are. Say you have two objects: my_form (DTML Document) my_target (Python Script) When a client makes a request for my_form, they are *calling* the my_form object. Since this object returns HTML when called, they get a nice-looking web form that includes a tag like: <form method=post action=my_target>
From this point on, you are **not** calling my_form any more. Any calculations that must be done by the my_form object must already be done by this point.
Submitting this form calls my_target. Any calculations performed by my_target will be done in the context of how my_target is set up and what request you call it with. The my_form object has no direct relevance at this point. If you need for my_target to know the title property of the my_form object that created the form, you'll want to include something like this in my_form: <input type=hidden value=<dtml-var title>> This way, you're evaluating title in the context of the correct object and passing that value along to the object you actually want to do something with it. Of course, DTML Methods don't have their own namespcaes so that won't work in your case. You can work around it (or cut & paste your code into a DTML Document object), but it may be just as easy to hand code it. HTH, Dylan
On Tue, 2003-05-13 at 10:46, Dylan Reinhardt wrote:
<input type=hidden value=<dtml-var title>>
One quick correction/note: The above will work correctly only if the title contains no spaces. A more generally useful tag would be: <input type=hidden value="<dtml-var title>"> Dylan
participants (5)
-
Alexis Roda -
Dylan Reinhardt -
Paul Winkler -
Terry Hancock -
Wim Bekker