Zope
  Home arrow Zope arrow DTML Basics (part 3)
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? 
ZOPE

DTML Basics (part 3)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2002-07-02


    Table of Contents:
  • DTML Basics (part 3)
  • When In Rome...
  • A List In Time
  • An Easy Replacement
  • Bringing In The Database
  • Digging Deeper

  • 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 3)
    ( Page 1 of 6 )

    Last time out, DTML Basics demonstrated conditional statements. This time around, it's time to study loops...which, in the DTML world, aren't exactly what you're used to. Take a look.If you've been following along, you now know how to incorporate decision-making constructs in your DTML code. As you saw in last week's episode, DTML comes with a fairly large family of conditional statements, which allow you to add business intelligence to your DTML scripts.

    But DTML is a full-fledged programming language, and one which allows you to do a lot more than nest "if" statements within each other. One of its cooler capabilities involves using powerful loop constructs to iterate over sequences of both variables and objects. This ability to create loops is not unique to DTML - almost every programming language on the planet allows you to do this - but DTML includes some fairly interesting twists to the traditional approach.

    Coincidentally, those twists just happen to be the subject of today's discussion. Keep reading - you've probably never seen this before.{mospagebreak title=Playing The Numbers} Before we get started, let's get the jargon straight - what's a sequence anyway?

    As traditionally understood, a "sequence" is a series of items, usually connected to each other by a logical thread. For example,

    0, 1, 2, 3, 4, 5...

    p, q, r, s, t...

    huey, dewey, louie...


    are all valid sequences

    In the Zope context, the definition of a sequence can be scoped down a little further - a sequence here is usually a set of objects. For example, if you create a folder in Zope, the objects stored within that folder can be considered a sequence. Or, if you retrieve a set of records from a database, the resultset returned can also be considered a sequence of data items.

    A sequence, however, is just one part of the jigsaw. In order to access the elements that make up a sequence, you usually need a programming structure that will iterate, or loop, through the sequence, processing each element in turn. This loop can be combined with decision-making logic (remember what you learnt last time?) to perform specific actions or execute specific commands while processing the elements in a sequence.

    In order to demonstrate this, let's create a sequence in Zope and write a loop to process it. Fire up Zope, log into the Zope management interface, and create an instance of the DTML Document object. Name it "SampleSequence" and fill it with the following code:

    <h3><dtml-var title_or_id></h3><br> <ul> <dtml-in expr="0, 1, 2, 3, 4, 5"> <li> I am <dtml-var sequence-item></li> </dtml-in> </ul>
    First, I've created a simple sequence by brute force - it contains numbers from 0 to 5. Then, the <dtml-in> tag is used to loop through the sequence, in a manner similar to the "for" loops that PHP and Perl programmers are familiar with. From the output, it's obvious that this script loops six times to display the items in the sequence.

    The individual elements of the sequence can be accessed via the special "sequence-item" variable. This is true in all cases, except when the items in the sequence are object that cannot be converted to strings.

    Save the code and view the output of the script - you should see something like this:

    * I am 0 * I am 1 * I am 2 * I am 3 * I am 4 * I am 5


     
     
    >>> 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 6 Hosted by Hostway
    Stay green...Green IT