.. include:: ../../Includes.txt .. highlight:: html ===== f:for ===== The `f:for` viewhelper is the preferred viewhelper to form loops and lists. Usage ===== Minimal usage: :: ... All parameters: :: ... Parameters ========== .. rst-class:: dl-parameters each :sep:`|` :aspect:`Condition:` required :sep:`|` :aspect:`Type:` array :sep:`|` :aspect:`Default:` NULL :sep:`|` The **array** or **object** to be iterated. as :sep:`|` :aspect:`Condition:` required :sep:`|` :aspect:`Type:` string :sep:`|` :aspect:`Default:` NULL :sep:`|` The **name of the variable** which contains the value for the current loop iteration. key :sep:`|` :aspect:`Condition:` optional :sep:`|` :aspect:`Type:` string :sep:`|` :aspect:`Default:` empty string :sep:`|` The **name of the variable** that contains the key of the current loop iteration. reverse :sep:`|` :aspect:`Condition:` optional :sep:`|` :aspect:`Type:` boolean :sep:`|` :aspect:`Default:` false :sep:`|` A **boolean flag**. Use *true* to reverse the sequence. *Examples of true:* `reverse="true"`, `reverse="1"`, `reverse="abc"`. *Examples of false:* `reverse="false"`, `reverse="0"`, `reverse=""`. iteration :sep:`|` :aspect:`Condition:` optional :sep:`|` :aspect:`Type:` string :sep:`|` :aspect:`Default:` NULL :sep:`|` The **name of a variable** that holds the iteration data of each loop. *Example:* `iteration="iterator"`. Iteration data can then be accessed like `{iterator.index}`, `{iterator.cycle}`, `{iterator.total}`, `{iterator.isEven}`, `{iterator.isOdd}`. *Attention:* `iterator.cycle` is just a simple counter. It has nothing to do with the viewhelper `f:cycle`. Examples ======== Example: Exhaustive usage ------------------------- 1. Page typoscript template: .. code-block:: typoscript page = PAGE page { 10 = FLUIDTEMPLATE 10.file = fileadmin/FluidForLoopExample.html } 2. Fluid html template in file :file:`fileadmin/FluidForLoopExample.html`::

FluidForLoopExample.html


Legend:

01 = employee.first_name
02 = employee.city
03 = itemkey
04 = iterator.index
05 = iterator.cycle
06 = iterator.isFirst
07 = iterator.isLast
08 = iterator.isOdd
09 = iterator.isEven
10 = iterator.total

reverse = "false"

01 02 03 04 05 06 07 08 09 10
{employee.first_name} {employee.city} {itemkey} {iterator.index} {iterator.cycle} {iterator.isFirst} {iterator.isLast} {iterator.isOdd} {iterator.isEven} {iterator.total}
3. Result for `reverse="false"`: .. figure:: For.rst.001.png :class: with-shadow With `reverse="false"` items appear in normal (default) order. 4. Result for `reverse="true"`: .. figure:: For.rst.002.png :class: with-shadow With `reverse="true"` items appear in reversed order. Everything else remains. Example: Minimum usage ---------------------- ::
{employee.first_name} {employee.city}
This creates a new table row for each of the entries in the 'employee' array. Example: Iterator usage ----------------------- :: {employee.first_name} {employee.city}
List of employees
Iteration beginning with 0: {iterator.index} Iteration beginning with 1: {iterator.cycle}
Number of employees: {iterator.total}