Specification: isloop

isloop Element

Create loops for flow control.

Syntax

<isloop
  items=item_object
  alias="alias_name"
  status="status_name"
  begin=start_index
  end=stop_index
  step=increment_index
>
  <!-- ... -->
</isloop>

items

Required

Allowed data type: expression.

You must include either items or iterator, but not both:

  • items = item_object item_object is an expression that returns an object to iterate over. Attributes iterator and items can be used interchangeably.

iterator

Required

Allowed data type: expression.

You must include either items or iterator, but not both:

  • iterator = iter_object iter_objectis an expression that returns an object to iterate over. Attributes iterator and items can be used interchangeably.

itemsis preferred.

var

Name of the variable referencing the object in the iterable collection referenced in the current iteration.

You must include one of the following but not both:

  • var = var_name var_name is the name of a variable referencing the object in the iterable collection referenced in the current iteration.

alias

Name of the variable referencing the object in the iterable collection referenced in the current iteration.

You must include one of the following but not both:

  • alias = alias_name alias_name is the name of a variable referencing the object in the iterable collection referenced in the current iteration.

var is preferred.

status

status_name is the variable name referencing the loop status object. The loop status is used to query information such as the counter or whether it's the first item.

If status is specified, a loop status object is assigned to the given variable name. Below are the properties of the loop status object:

AttributeDescription
countThe number of iterations, starting with 1.
indexThe current index into the set of items, while iterating.
firstTrue, if this is the first item while iterating (count == 1).
lastTrue, if this is the last item while iterating.
oddTrue, if count is an odd value.
evenTrue, if count is an even value.

begin

Allowed data type: expression.

start_index is an expression specifying a begin index for the loop. If the begin is greater than 0, the <isloop> skips the first x items and starts looping at the begin index. If begin is smaller than 0, 0 is used as the begin value.

end

Allowed data type: expression.

stop_indexis an expression specifying an end index (inclusive). If end is smaller than begin, the <isloop> is skipped.

step

Allowed data type: expression.

increment_index is an expression specifying the step used to increase the index. If step is smaller than one, one is used as the step value.

Purpose

With <isloop> you can loop through the elements of a specified iterator. As an example, you can list data like categories, products, shipping, and payment methods. <isloop> statements can be nested in one another.

Supporting Tags

  • Use <isbreak> to unconditionally terminate a loop.
  • Use <isnext> to jump forward in a loop

See isbreak and <isnext for more information.

Example

<isloop iterator="${pdict.Basket.products}" alias="product">
  <isprint value="${product.name}"> <br/>
</isloop>

Note The previous pdict.Basket is merely an example of using the Pipeline Dictionary as it relates to the Reference Application. It isn't the same as the Basket class in Salesforce B2C Commerce server-side JavaScript.