Zope
  Home arrow Zope arrow Page 3 - DTML Basics (part 4)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
ZOPE

DTML Basics (part 4)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek