Loops are blocks of code that are executed repeatedly until a specific condition is met. Use <ISLOOP>
to loop through the elements of a specified iterator. For example, using <ISLOOP>
you can list iterable data like categories, products, shipping, or payment methods on a webpage.
Multiple <ISLOOP>
statements can be nested to construct more complex loop structures.
<ISLOOP>
has the two supporting tags <ISBREAK>
and <ISNEXT>
. Both tags can only be used inside the <ISLOOP>
tag.
Use <ISBREAK>
within an <ISLOOP>
construct to unconditionally terminate the loop. If <ISBREAK>
is used in a nested loop, it will only terminate the inner loop.
Usually, the <ISBREAK>
tag is used within <ISIF>
tags to terminate a loop when a certain condition is met.
Use <ISNEXT>
to jump forward to the next element in an iterator. In nested loops, this tag affects only the iterator of the inner loop. In case an iterator has already reached its last element, or an iterator is empty when an <ISNEXT>
is processed, the loop is terminated instantly.
<isloop iterator = "{ISML variable identifier}" [ alias = "{simple name}" ] [ counter = "{counter name}" ] > ... some HTML and ISML code ... [<isnext>] [<isbreak>] </isloop>
Use <ISLOOP>
's alias
attribute to avoid naming conflicts:
<ISLOOP iterator = "basket:Offering" alias = "Off"> <ISPRINT value = "#Off:Name#"> <BR> </ISLOOP>
Use <ISLOOP>
's counter
attribute to define a variable that gets incremented by one on each loop iteration:
<isloop iterator="iterator1" alias="element1" counter="c1"> <h3><isprint value="#element1#"></h3> <ul> <isloop iterator="iterator2" alias="element2" counter="c2"> <li> <isprint value="#c1#">. <isprint value="#c2#"/>. <isprint value="#element1#"/> <isif condition="#c2 == 1#"> (This is the first element of the inner list) </isif> </li> </isloop> </ul> </isloop>
In conditional templates, <ISLOOP>
is often used in combination with the ISML Function - hasElements()and ISML Function - hasNext()functions.
hasElements()
checks if an iterator stored in the pipeline dictionary has any elements.
hasNext() checks whether the actual iterator instance in the current loop has any more elements. This is useful in cases where the last loop element needs special treatment. See ISML Function - hasElements(), ISML Function - hasLoopElements()and ISML Function - hasNext()for details.
<ISLOOP iterator="foo"> ... <ISIF condition="#hasNext(foo)#"> ... // do something except for last line </ISIF> ... </ISLOOP>
iterator
This attribute is required.
iterator = ISML variable identifier
Use this attribute to specify an iterator. Attributes of the iterator can be used in the loop within expressions. The iterator can be one of the following classes:
com.intershop.beehive.foundation.util.Iterable
java.util.Enumeration
java.util.Iterator
java.util.Collection
alias
This attribute is optional.
alias = simple name
Allows you to define an alias name that can be referenced instead of the often unwieldy variable identifier.
counter
This attribute is optional.
counter = counter name
Allows you to define a variable that contains the number of the current element in the iterator. The variable starts with 1.