---
title: "For ViewHelper <f:for>"
manual: "Fluid Explained"
version: "main"
permalink: "https://docs.typo3.org/permalink/fluid:typo3fluid-fluid-for"
source: "ViewHelpers/Fluid/For.rst"
rendered: "2026-09-26T08:24:58+00:00"
---

# For ViewHelper `<f:for>` {#typo3fluid-fluid-for}

> [!NOTE]
> This reference is part of the documentation of Fluid Standalone.
> If you are working with Fluid in TYPO3 CMS, please refer to
> [TYPO3's ViewHelper reference](https://docs.typo3.org/other/typo3/view-helper-reference/14.3/en-us/Global/For.html) instead.

Loop ViewHelper which can be used to iterate over arrays.
Implements what a basic PHP `foreach()` does.

## Examples {#examples}

### Simple Loop {#simple-loop}

```php
<f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo">{foo}</f:for>

```

Output:

```php
1234

```

### Output array key {#output-array-key}

```php
<ul>
    <f:for each="{fruit1: 'apple', fruit2: 'pear', fruit3: 'banana', fruit4: 'cherry'}"
        as="fruit" key="label"
    >
        <li>{label}: {fruit}</li>
    </f:for>
</ul>

```

Output:

```php
<ul>
    <li>fruit1: apple</li>
    <li>fruit2: pear</li>
    <li>fruit3: banana</li>
    <li>fruit4: cherry</li>
</ul>

```

### Iteration information {#iteration-information}

```php
<ul>
    <f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo" iteration="fooIterator">
        <li>Index: {fooIterator.index} Cycle: {fooIterator.cycle} Total: {fooIterator.total}{f:if(condition: fooIterator.isEven, then: ' Even')}{f:if(condition: fooIterator.isOdd, then: ' Odd')}{f:if(condition: fooIterator.isFirst, then: ' First')}{f:if(condition: fooIterator.isLast, then: ' Last')}</li>
    </f:for>
</ul>

```

Output:

```php
<ul>
    <li>Index: 0 Cycle: 1 Total: 4 Odd First</li>
    <li>Index: 1 Cycle: 2 Total: 4 Even</li>
    <li>Index: 2 Cycle: 3 Total: 4 Odd</li>
    <li>Index: 3 Cycle: 4 Total: 4 Even Last</li>
</ul>
```

Go to the source code of this ViewHelper: [ForViewHelper.php (GitHub)](https://github.com/TYPO3/Fluid/blob/main/src/ViewHelpers/ForViewHelper.php).

**Arguments**

The following arguments are available for the for ViewHelper:

-   **as**

    -   *Type:* string
    -   *Required:* true

    The name of the iteration variable

-   **each**

    -   *Type:* array
    -   *Required:* true

    The array or \\SplObjectStorage to iterated over

-   **iteration**

    -   *Type:* string

    The name of the variable to store iteration information (index, cycle, total, isFirst, isLast, isEven, isOdd)

-   **key**

    -   *Type:* string

    Variable to assign array key to

-   **reverse**

    -   *Type:* boolean
    -   *Default:* false

    If true, iterates in reverse
