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.
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.