Home arrow Zope arrow Page 2 - DTML Basics (part 3)

When In Rome... - Zope

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.

TABLE OF CONTENTS:
  1. DTML Basics (part 3)
  2. When In Rome...
  3. A List In Time
  4. An Easy Replacement
  5. Bringing In The Database
  6. Digging Deeper
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 5
July 02, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Not impressed yet? Let's alter the code a little to see what else you can do with sequences.

<h3><dtml-var title_or_id></h3> <br> <dtml-in expr="'apple', 'banana', 'orange', 'apricot', 'grape'"> <sequence-length> <dtml-if sequence-start><i>Here's where it all starts</i><br></dtml-if> My name is <dtml-var sequence-item>, my sequence position is <dtml-var sequence-number>, and my index is <dtml-var sequence-index>.<br> <dtml-if sequence-end><i>And here's where it ends</i><br></dtml-if> </dtml-in>
Now take a look at the output.

Here's where it all starts My name is apple, my sequence position is 1, and my index is 0. My name is banana, my sequence position is 2, and my index is 1. My name is orange, my sequence position is 3, and my index is 2. My name is apricot, my sequence position is 4, and my index is 3. My name is grape, my sequence position is 5, and my index is 4. And here's where it ends
This example uses a couple of new variables to add new functionality to the example. First, the "sequence-number" variable represents the position of the current item in the sequence, while the "sequence-index" variable provides an alternative zero-based indexing mechanism that serves the same purpose. And the "sequence-start" and "sequence-end" variables provide an easy way to find out if you're at the beginning or end of the sequence - the former is true when the current item is the first element of your sequence and the latter is true when the current element is the last element of the sequence.

One more interesting variable (which I haven't demonstrated in the example above) is the "sequence-length" variable, which returns the number of items present in the sequence. There's also the "sequence-roman" variable, which can be used to display the sequence number using lower-case Roman numerals, the "sequence-Roman" for upper-case Roman numerals, and the "sequence-letter" and "sequence-Letter" variables for alphabetical indexing.

 
 
>>> More Zope Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

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

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: