Iterating collections with isloop and its status object
Key Takeaway
In an <isloop>, the loop status object's count is the number of iterations the loop actually performs, starting at 1. index is the item's position in the collection, so the two differ when begin is greater than 0.
The <isloop> tag repeats a block of ISML template markup once for each element in a collection, such as a list of categories, products, shipping methods, or payment methods. An optional loop status object tells the template where it is in the loop. The tags <isbreak/>, <isnext/>, and <iscontinue/> change how the loop moves forward.
How to loop through a collection
The <isloop> tag loops through the elements of an iterator and outputs its body once per element. You can nest <isloop> statements inside one another.
- Name the collection with exactly one of the
itemsoriteratorattributes. Never use both. Each takes an expression that returns the object to iterate over. The two attributes are interchangeable, butitemsis preferred. - Name the current element with exactly one of the
varoraliasattributes. Never use both, and prefervar. The variable points to the element being processed in the current iteration. - Put the markup to repeat inside the loop body. Use the variable there to read the current element.
<isloop items="${pdict.Articles}" var="article">
<isprint value="${article.title}">
</isloop>Here items points the loop at pdict.Articles. var names the current element article, so the body prints one article title per pass.