We'll begin with something interesting. Create a DTML Document named "WithOrWithoutYou" and insert the following code.
<b>
The value of "id" is <dtml-var id><br>
The value of "icon" is <dtml-var
icon><br>
The value of "me" is <dtml-var me>
</b>
Now, call this script with three parameters, like this:
http://localhost:8080/DTML%20Basics/WithOrWithoutYou?id=1234&icon=folder
&me=
John
In other words, I'm explicitly passing it values for the "id", "icon" and "me"
variables. But when I view the output of the script, I see something completely different:
The value of "id" is WithOrWithoutYou
The value of "icon" is misc_/OFSP/dtmldoc.gif
The
value of "me" is John
Of the three values passed, only one appeared correctly. How come?
Take a look at the variable names used in the example. While the third one does not ring a bell, the first two are among the default properties associated with each and every Zope object.
Now, if you go back a little, you'll remember a little thing called acquisition, a concept I took great pains to explain - basically, the process by which Zope tries to find a value for a variable. As I said before, Zope will first look for the variable value in the current folder and then traverse upwards to the root folder in search of it. If it is still unsuccessful, it looks in a couple of other places for the missing information; these places include cookies and form data sent using POST or GET methods.
Now, the entire gamut of objects and locations listed above represent a nebulous entity that Zope refers to as the "namespace". By default, Zope places some default objects in this namespace when it starts up. Subsequent objects are added to this "stack" as and when they are invoked.
Consequently, when you load the DTML Document above, it is pushed to the top of the namespace stack along with its "id" and "icon" properties. When DTML tries to replace the value of the variables "id" and "icon" in the DTML Document, it encounters these two properties at the top of the namespace stack before even getting around to looking in the query string (which are always located at the bottom of the namespace stack). Which explains why the values passed on the query string never show up in the output of the script.
That said, since no value exists for the variable "me" in the namespace stack, Zope will finally get around to looking in the GET query string, locate the variable value and print it.
Obviously, this behaviour isn't always what you want. Which is where the <dtml-with> tag comes in.