easier way to get this() from DTML Document?
In order to get the real context when I call a Python Script from a DTML Document, I've found that I need to do something besides just looking at the context (because it's the container of the DTML Document). For now, I'm explicitly passing this() <dtml-var "standard_html_footer(this=this())"> and then I test if it's set in my Python Script. If it is, I use it. Otherwise I use the context. Is there a way around this? I don't want users to have to put in the "this=this()" junk. Can I somehow pry open the '_' TemplateDict enough to get the same info? Thank you. --kyler
Kyler B. Laird writes:
In order to get the real context when I call a Python Script from a DTML Document, I've found that I need to do something besides just looking at the context (because it's the container of the DTML Document). Interesting behaviour of DTML Document....
For now, I'm explicitly passing this() <dtml-var "standard_html_footer(this=this())"> and then I test if it's set in my Python Script. If it is, I use it. Otherwise I use the context.
Is there a way around this? I don't want users to have to put in the "this=this()" junk. Can I somehow pry open the '_' TemplateDict enough to get the same info? The namespace has an *attribute* "this". It is the top level DTML object's client: the DTML document (its explicit acquisition wrapper!) in the case of a top level DTML document.
Thus, if you bind the namespace (to "_"), you can use "_.this" in your Python script. Alternatively, you can use "REQUEST.PUBLISHED". This is the published object. In your case, it would be the DTML Document (its implicit acquisition wrapper). Both approaches will break down, if your document is called indirectly. However, "_['this']" should work for any DTML document, but not for other object types. Dieter
participants (2)
-
Dieter Maurer -
Kyler B. Laird