Home arrow Zope arrow Page 2 - DTML Basics (part 4)

With Or Without You - Zope

In this concluding article, dip your toes in the waters of more advanced DTML programming, with explanations of the , and tags.

TABLE OF CONTENTS:
  1. DTML Basics (part 4)
  2. With Or Without You
  3. A Polite Request
  4. Let Me In
  5. Climbing A Tree
  6. The Real Thing
  7. Call Of The Wild
  8. The Writing On The Wall
  9. Endzone
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 5
July 17, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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.

 
 
>>> More Zope Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZOPE ARTICLES

- Creating Zope Products
- Plone Content Types With Archetypes
- Flat User Management in Zope
- Creating Basic Zope Applications
- Getting started with Zope for Linux and Sola...
- ZPT Basics (part 4)
- ZPT Basics (part 3)
- ZPT Basics (part 2)
- ZPT Basics (part 1)
- Exception Handling In DTML
- DTML Basics (part 4)
- DTML Basics (part 3)
- DTML Basics (part 2)
- DTML Basics (part 1)
- Using Zope With Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: