Not impressed yet? Let's alter the code a little to see what else you can do with sequences.
<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>,
sequence position is <dtml-var
sequence-number>, and my index is <dtml-var
<dtml-if sequence-end><i>And here's where it ends</i><br></dtml-if>
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
orange, my sequence position is 3, and my index is 2. My name is
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.