Start page / Template development / Template syntax / System objects / #for

#forAvailable from FirstSpirit Version 4.0

The #for system object is available for use within a $CMS_FOR(...)$ instruction. You can use this object to determine whether the current element is the first one or the last one. It is also possible to determine which number element is currently being rendered.

The individual calls and what they mean:

Call

Definition

Return data type

#for.BREAK

This call can be used to terminate the loop prematurely, e.g., if the element being sought has been found: $CMS_SET(void, #for.BREAK)$

-

#for.CONTINUE or
#for.CONT

This call is used to perform the next loop iteration. The current element is skipped: $CMS_SET(void, #for.CONTINUE)$

-

#for.index

Outputs the element index.
This can be used to determine which number element is currently being rendered.
Counting starts at 0.

Integer

#for.isFirst

Determines whether or not the element currently being rendered is the first one

Boolean

#for.isLast

Determines whether or not the element currently being rendered is the last one

Boolean

#for.name

System object name.
The following is returned: #for.

String

   

Examples of #for

Below are some examples of how to use the instruction within templates. The purpose of the examples is to point out the precise effect of the instruction and to assist template developers in creating their own templates.

Important The examples shown here must be adapted before they can be used within a project. For example, variable names need to be changed to the specific variable names of the project in which the instruction is to be used.

1st example: Table with exponential calculations

$CMS_FOR(exp, [0 .. 10])$
$CMS_IF(#for.isFirst)$
<table>
$CMS_END_IF$
<tr>
<td><b>2 ^ $CMS_VALUE(exp)$</b></td>
<td>$CMS_VALUE(2.pow(exp))$</td>
</tr>
$CMS_IF(#for.isLast)$
</table>
$CMS_END_IF$
$CMS_END_FOR$

This example shows a base-2 exponential calculation with exponents 0 to 10. An opening table tag is output before the first element (0). Two columns are output for each exponent as well. The first one contains 2 ^ followed by the current exponent and the second one contains the calculated result. The closing table tag is then output after the final element (10).

Output:

<table>
<tr>
<td><b>2 ^ 0</b></td>
<td>1</td>
</tr>
<tr>
<td><b>2 ^ 1</b></td>
<td>2</td>
</tr>
<tr>
<td><b>2 ^ 2</b></td>
<td>4</td>
</tr>
<tr>
<td><b>2 ^ 3</b></td>
<td>8</td>
</tr>
<tr>
<td><b>2 ^ 4</b></td>
<td>16</td>
</tr>
<tr>
<td><b>2 ^ 5</b></td>
<td>32</td>
</tr>
<tr>
<td><b>2 ^ 6</b></td>
<td>64</td>
</tr>
<tr>
<td><b>2 ^ 7</b></td>
<td>128</td>
</tr>
<tr>
<td><b>2 ^ 8</b></td>
<td>256</td>
</tr>
<tr>
<td><b>2 ^ 9</b></td>
<td>512</td>
</tr>
<tr>
<td><b>2 ^ 10</b></td>
<td>1024</td>
</tr>
</table>

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.13 | Data privacy