Not impressed yet? Let's alter the code a little to see what else you can do with sequences. Now take a look at the output. How does this work? Well, you may remember, from your DTML exploits, that all sequences have built-in variables that can be used to identify the current pointer position within the sequence. The "number" variable represents the position of the current item in the sequence, while the "index" variable provides an alternative zero-based indexing mechanism that serves the same purpose. And the "start" and "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 the sequence and the latter is true when the current element is the last element of the sequence. Now, in order to access these values in your Zope Page Templates, you need to use one or more TALES expressions. Here are the ones I've used: repeat/fruits/start - A TALES expression for the value of the "start" variable repeat/fruits/number - A TALES expression for the value of the "number" variable repeat/fruits/index - A TALES expression for the value of the "index" variable repeat/fruits/end - A TALES expression for the value of the "end" variable You may remember, from earlier articles in this series, that every TALES path must begin with a variable name. "repeat" is one such pre-defined variable, and it stores information on the start and end position, number, index and length of the sequence. This information can then be accessed using a three-part path, such as the ones demonstrated above The example you just saw used a simple sequence. However, you can also loop over a collection of objects using the same technique. Take a look at a simple example that lists the objects in the current folder. Here's the output: Here, I've used the "container" built-in variable together with the "objectIds" variable, which returns a sequence with the list of objects in the current folder.
blog comments powered by Disqus |