Creating a variable in a DTML method that may be modified
Hello. Does anyone know how to create a variable in a DTML method which may be updated by a Python script? I am currently using the set method of the REQUEST object to create a variable. However, creating a variable in this fashion renders it permanent. Any help would be appreciated. Thanks. -Asad __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com
At 11:34 AM 2/4/2003, Asad Habib wrote:
Hello. Does anyone know how to create a variable in a DTML method which may be updated by a Python script? I am currently using the set method of the REQUEST object to create a variable. However, creating a variable in this fashion renders it permanent.
I'm not aware of any degree of "permanence" in REQUEST variables, so I doubt that's your problem. Use REQUEST.set() to _create_ a variable and assign its initial value. After that point, just use plain old dtml-call and ordinary Python expressions to manipulate the value of the variable. Not all built-in methods of Python types are supported, but there's enough available to do pretty much anything you need to do. If you're having difficult making a particular assignment, it would be helpful if you provide more detail. And stop cross-posting these questions to Zope-dev... that is *not* the appropriate forum for usage-related questions. HTH, Dylan
Other than explictly passing arguments, the shareable namespace, _, is the logical place to exchange such variables btw DTML and Script(Python). However, the namespace object, a TemplateDict, only allows you to PUSH/POP spaces, not set/change variables, so you have to find or provide something in the namespace that is mutable. You found REQUEST, and there is also SESSION. And you can provide your own mutable namespace as a dictionary: ----- cut here ----- DTML Method <dtml-let myvars="{ 'somevar': 5 }"> <!-- Create My Own Namespace --> <dtml-with myvars mapping> <!-- and Push onto the Search Stack --> Before: <dtml-var somevar> <dtml-call mypython> After: <dtml-var somevar> </dtml-with> </dtml-let> ----- cut here ----- Script(Python) Method ## Script (Python) "mypython" ##bind container=container ##bind context=context ##bind namespace=_ ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## _['myvars']['somevar'] = 7 When the DTML Method is invoked, this will print: Before: 5 After: 7 When the end of the DTML-WITH is reached, the namespace will be popped/discarded, so it won't be permanent, as you wish to avoid. Hope this helps, Jeff Rush Asad Habib wrote:
Hello. Does anyone know how to create a variable in a DTML method which may be updated by a Python script? I am currently using the set method of the REQUEST object to create a variable. However, creating a variable in this fashion renders it permanent. Any help would be appreciated. Thanks.
participants (3)
-
Asad Habib -
Dylan Reinhardt -
Jeff Rush