Start page
Start page

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

#forAvailable from FirstSpirit Version 4.0

The system object: #for is available within a $CMS_FOR(...)$ instruction. The object can be used to determine whether the current element is the first or the last element. Further, it is also possible to determine which element is currently being rendered.

The individual invocations and their meaning:

Invocation

Meaning

Return data type

#for.index

Output of the element index.
This can be used to determine which element is currently being rendered.
Counting begins with 0.

Integer

#for.isFirst

Determination whether the current element to be rendered is the first element or not.

Boolean
(Boolean value)

#for.isLast

Determination whether the current element to be rendered is the last element or not.

Boolean
(Boolean value)

#for.name

Name of the system object.
The return is: #for.

String
(character string)

   

Examples of #for

Several examples of use of the instruction within templates are shown in the following. The examples are intended to clearly show the specific effect of the instruction and provide help for the template developer when creating their own templates.

Important The examples displayed here must be adjusted for use within a project! For example, variable names must 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$

In the example an exponential calculation is carried out to base 2 with the exponents 0 to 10. For the first element (0) an opening table tag is output. For each exponent an additional two columns are output. The first column contains 2 ^ followed by the current exponent, the second column contains the calculated result. Then, after the last element (10) the closing table tag is output.

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 - 2014 e-Spirit AG | All rights reserved. | Last change: 2008-01-16