Zope
  Home arrow Zope arrow Page 3 - DTML Basics (part 2)
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 2)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2002-06-05


    Table of Contents:
  • DTML Basics (part 2)
  • If Only...
  • Comparing Apples And Oranges
  • Welcome To The Matrix
  • Celluloid Dreams
  • Paring It Down
  • Deeper And Deeper
  • Submitting To The King

  • 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 2) - Comparing Apples And Oranges
    (Page 3 of 8 )

    Theexample you've just seen was very rudimentary. To really add somepunch, you need to know how to construct what the geeks call aconditional statement. And the very basis of a conditional statement iscomparison - for example, "if this is equal to that, do thus and such".

    Since Zope is built around Python, and Python comes with a bunch ofuseful operators designed specifically for use in conditionalstatements, you can use Python operators to build conditional statementsin your DTML. Here's alist:

    Assume delta = 12 and omega = 9

    Operator What It Means Expression
    Evaluates To
    ------------------------------------------------------------------------
    -

    == is equal to delta == omega False

    != is not equal to delta != omega True

    is greater than delta > omega True

    < is less than delta < omega False

    = is greater than or equal to delta >= omega True

    <= is less than or equal to delta <= omega False
    These comparison operators can be used for both strings and numbers. Apositive result returns true (1), while a negative result returns false(0).

    Here's an example, a DTML Method named "access", which illustrates howthese can be used:

    <dtml-if expr="name == 'neo'">
    <font face="Arial" size="-1">
    Welcome to the Matrix, Neo. Access granted.
    </font>
    </dtml-if>

    <dtml-if expr="name != 'neo'">
    <font face="Arial" size="-1">
    I wonder if you've heard of Shakespeare, <dtml-var name>.
    <p>He postulated that a rose by any other name would smell just as
    sweet.</p> <p>Unfortunately for you, I disagree. Access denied.</p>
    </font> </dtml-if>
    Now, if you view this example in your browser, you'll see an ugly Zopeerror - this is because Zope cannot locate the variable "name", despiteits best attempts to acquire it from the global namespace. Therefore, inorder to see this script work properly, you need to first make sure thata variable named "name" actually exists. You can do this by adding thisvariable to the REQUEST object, via the URL GET method; just call theDTML script using a URL similar to this one:

    http://localhost:8080/DTML%20Basics/access?name=Joe

    Here's the output:.

    I wonder if you've heard of Shakespeare, Joe.

    He postulated that a rose by any other name would smell just as sweet.

    Unfortunately for you, I disagree. Access denied.

    Flip it around to see what it looks like when the variable named "name"holds the value "neo". Here's the URL to use,

    http://localhost:8080/DTML%20Basics/access?name=neo

    and here's the output:

    Welcome to the Matrix, Neo.
    In this case, since the conditional expression in the "if" statementevaluates to true, the output displayed by the script will be different.

    There's one more thing that needs to be explained in the code above -the "expr" keyword. Normally, you can directly test whether or not avariable exists using the <dtml-var> or the <dtml-if> tags (as I've donein my very first example). However, if you want to do anything morecomplicated - for example, evaluate a DTML expression such as

    "name == 'neo'"
    or

    "temperature > 98.6"
    - you need to first tell the DTML interpreter that you're talking aboutan expression and not a variable. And that's where "expr" comes in - itlets Zope know that it's dealing with a conditional expression, and notjust a regular variable.

     
     
    >>> 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-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek