Proper way to set variables
Heh, feels strange to reply to myself, but as I got no replies before, maybe I need to elaborate a bit. The original question is below. My main confusion is just how do I set a variable that is dynamically scoped without having to use dtml-with or dtml-let, both of which require matching closing tags? the REQUEST.set was used, but for some reason, when calling some functions, it would suddenly disappear and an error would result. So I am completely puzzled about it. Thanks, John John Goerzen <jgoerzen@complete.org> writes:
Hi,
I have a method that is called as part of the branches_expr of a tree tag. (Thanks for the pointer to dtml-return, BTW!)
I have a problem. I have some parameters to this method that I want to be optional. I was testing for them with dtml-if, and then calling REQUEST.set to set them to an appropriate value if they were not passed in to this DTML method.
This seemed to work. However, when this was called from within the tree tag, for some reason, it complains that REQUEST is not set. I have tried every way I can think of to pass in both REQUEST and _, to no avail.
My only other way that I know to set these things is with dtml-with, but since this is only called in some cases, there is a scoping problem; the closing tag would have to occur after the /dtml-if. So, this is out.
I guess I have several questions:
* What's the solution to this particular problem?
* What's the preferred way to create or set variables in DTML?
* Why does REQUEST sometimes disappear?
I understand the search logic just fine (this is nicely explained in the DTML book). But, it seems to be ignored; why is REQUEST no longer present, and what can be done to remedy it?
Thanks,
John Goerzen
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce
For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
-- John Goerzen Linux, Unix consulting & programming jgoerzen@complete.org | Developer, Debian GNU/Linux (Free powerful OS upgrade) www.debian.org | ----------------------------------------------------------------------------+ The 11,979,300th prime number is 217,247,021.
At 02:02 PM 9/8/99 -0500, John Goerzen wrote:
Heh, feels strange to reply to myself, but as I got no replies before, maybe I need to elaborate a bit. The original question is below.
My main confusion is just how do I set a variable that is dynamically scoped without having to use dtml-with or dtml-let, both of which require matching closing tags?
FYI, I have just written a patch for DT_Let.py that adds two new tags, 'local' and 'set'. They are used like this: <!--#local myvar1="0" myvar2=somevar--> <!--#set myvar1="myvar1+myvar2"--> ... <!--#set myvar2="myvar2+1"--> <!--#/local--> Both <!--#local--> blocks and <!--#set--> tags are dynamically scoped and <!--#set--> can be used anywhere as long as there is an enclosing <!--#local--> block defining the variable you want to set. You can only set variables which are defined by the innermost <!--#local--> block, but you can reset their value any number of times, even within the same <!--#set--> tag. I am currently testing this code in an alpha app, but will be submitting it some time in the near future to Digital Creations for consideration of inclusion in future Zope versions.
participants (2)
-
John Goerzen -
Phillip J. Eby