Zope
  Home arrow Zope arrow Page 3 - DTML Basics (part 4)
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ZOPE

DTML Basics (part 4)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2002-07-17

    Table of Contents:
  • DTML Basics (part 4)
  • With Or Without You
  • A Polite Request
  • Let Me In
  • Climbing A Tree
  • The Real Thing
  • Call Of The Wild
  • The Writing On The Wall
  • Endzone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    DTML Basics (part 4) - A Polite Request
    (Page 3 of 9 )

    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


     

       

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway