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

    Dell PowerEdge Servers

    DTML Basics (part 2) - Celluloid Dreams
    (Page 5 of 8 )

    For situations whicharen't entirely black and white, DTML also allowsfor multiple conditional branches, via the "if-elif-else" construct. Atypical "if-elif-else" statement block would look like this:

    <dtml-if "first condition is true">
    do this!
    <dtml-elif "second condition is true">
    do this!
    <dtml-elif "third condition is true">
    do this!
    ... and so on ...
    <dtml-else>
    do this!
    </dtml-if>
    And here's an example that demonstrates how to use it. Create a DTMLDocument named "selectDay".

    <html>
    <head>
    <style type="text/css">
    td {font-family: Arial;}
    </style>
    </head>

    <body>

    <font face="Arial" size="+2">
    Movie Schedule
    </font>

    <form method="POST" action="showMovieForTheDay">
    <table cellspacing="5" cellpadding="5" border="0">

    <tr>
    <td align="center">
    Pick a day
    </td>
    <td align="right">
    <select name="day">
    <option value="Monday">Monday
    <option value="Tuesday">Tuesday
    <option value="Wednesday">Wednesday
    <option value="Thursday">Thursday
    <option value="Friday">Friday
    <option value="Saturday">Saturday
    <option value="Sunday">Sunday
    </select>
    </td>
    </tr>

    <tr>
    <tr>
    <td colspan="2" align="center">
    <input type="submit" value="Hit me!">
    </td>
    </tr>

    </table>
    </form>
    </body>

    </html>
    As you can see, this is simply a form which allows you to pick a day ofthe week.

    The real work is done by the DTML Method "showMovieForTheDay".

    <html>
    <head>
    <basefont face="Arial">
    </head>

    <body>
    Here is the movie for <dtml-var day> on your favorite channel:

    <br>
    <dtml-if expr="day == 'Monday'">
    <p><b>Dead By Monday</b> - directed by <b>Curt Truninger</b> <dtml-elif
    expr="day == 'Tuesday'"> <p><b>Never On Tuesday</b> - directed by
    <b>Adam Rifkin</b></p> <dtml-elif expr="day == 'Wednesday'"> <p><b>Any
    Given Wednesday</b> - directed by <b>Neil Mandt</b></p> <dtml-elif
    expr="day == 'Thursday'"> <p><b>Thursday Afternoon</b> - directed by
    <b>Clay Westervelt</b></p> <dtml-elif expr="day == 'Friday'">
    <p><b>Friday The 13th</b> - directed by <b>Sean S. Cunningham</b></p>
    <dtml-else> <p><b>Hey, Mr. Couch Potato! It's the weekend...go out and
    get some exercise!</b></p> </dtml-if> <br>

    </body>
    </html>
    In this case, we've used the "if-elif-else" control structure to displaythe appropriate move for the day.

    There's one important point to be noted here: as soon as one of the"if"statements within the block is found to be true, Zope will execute thecorresponding code, skip the remaining "if" statements in the block,andjump immediately to the lines following the entire "if-elif-else"block.

    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 1 hosted by Hostway