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

A Polite Request - 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
Take a look at this next example, which demonstrates how the <dtml-with> tag can be used to work around the problems encountered in the previous example.

<b> <dtml-with REQUEST only> <dtml-if id>The value of "id" is <dtml-var id><br></dtml-if> <dtml-if icon>The value of "icon" is <dtml-var icon><br></dtml-if> <dtml-if me>The value of "me" is <dtml-var me><br></dtml-if> </dtml-with> </b>
Now, take a look at the output:

The value of "id" is 1234 The value of "icon" is folder The value of "me" is John
How did this work? The <dtml-with> tag - it is used to push a object to the top of the DTML namespace. As a result, Zope will look for all the variables in this object first.

<dtml-with REQUEST only>
The above statement pushes the REQUEST object to the top of the namespace stack. This object consists of the CGI environment variables, cookies and form data sent using the GET and POST methods.

For a quick glimpse into this object, create a new DTML Document with the following code.

<dtml-var REQUEST>
And when you view the output of this script, you'll see exactly what the REQUEST object contains.

The additional "only" attribute in the call to <dtml-with> tells Zope that it should not look beyond the REQUEST object for these values. Why bother with this extra tag? Consider what will happen if you don't pass a value for the "id" parameter - once Zope checks the REQUEST object and fails to find a value for this variable, it will proceed down the namespace stack to see if a value exists anywhere else. And we know it does - which could lead to unexpected results. The "only" attribute is the only (pardon the pun) way to ensure that this does not happen.

<dtml-if id>The value of "id" is <dtml-var id><br></dtml-if> <dtml-if icon>The value of "icon" is <dtml-var icon><br></dtml-if> <dtml-if me>The value of "me" is <dtml-var me><br></dtml-if>
The rest of the code checks to see whether the named variable exists in the REQUEST object, and only displays the corresponding line of output if it does. Again, this is a good way to avoid the unexpected, and to prevent bugs creeping 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: