Maple Engine
A collection and it's keys, often referred to as a record-set, are accessed differently and requires the indication of a key name. Keys are indicated through brackets and optional quotes enclosing the key name.
For example, a variable representing an account may have first and last name variables. These values can be accessed as myAccount['FirstName'] or myAccount['LastName']. You can use single, double or no quotes so myAccount['FirstName'] is the same as myAccount["FirstName"] and myAccount[FirstName].
{ myAccount in accounts }
<div>{ myAccount['FirstName'] } { myAccount['LastName'] }</div>{ loop }
In this example, accounts is your collection list and myAccount is assigned a single collection for each iteration. Data is accessed using a collection variable.
Note: Special variables are in lower case.
The iteration variable holds the current iteration number of a loop, starting at 1. It can be used to add counts to your list or combined with first and last. The first and last variables are assigned numerical values related to iteration. Last is a number representing the last iteration of a loop while first is the opposite. We'll introduce an example later.
Let's take a look at the previous example with special variables and the leave statement implemented.
{ myAccount in accounts }
<div>{ interation } )</div>{ loop }
<div>{ myAccount['FirstName'] } { myAccount['LastName'] }</div>
{ interation = last }</hr>{ end }
{ interation = 3 }{ leave }{ end }
There are a few things to look at here
- The iteration variable is used as a counter for account records.
- Iteration is compared to the last iteration and if positive, a line is added.
- If iteration evaluates to 3 then the loop is stopped.

Add Your Feedback