---
title: "GroupedFor ViewHelper <f:groupedFor>"
manual: "Fluid Explained"
version: "main"
permalink: "https://docs.typo3.org/permalink/fluid:typo3fluid-fluid-groupedfor"
source: "ViewHelpers/Fluid/GroupedFor.rst"
rendered: "2026-10-08T14:12:40+00:00"
---

# GroupedFor ViewHelper `<f:groupedFor>` {#typo3fluid-fluid-groupedfor}

> [!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/GroupedFor.html) instead.

Grouped loop ViewHelper.
Loops through the specified values.

The groupBy argument also supports property paths.

Using this ViewHelper can be a sign of weak architecture. If you end up
using it extensively you might want to fine-tune your "view model" (the
data you assign to the view).

## Examples {#examples}

### Simple {#simple}

```php
<f:groupedFor each="{0: {name: 'apple', color: 'green'}, 1: {name: 'cherry', color: 'red'}, 2: {name: 'banana', color: 'yellow'}, 3: {name: 'strawberry', color: 'red'}}"
    as="fruitsOfThisColor" groupBy="color"
>
    <f:for each="{fruitsOfThisColor}" as="fruit">
        {fruit.name}
    </f:for>
</f:groupedFor>

```

Output:

```php
apple cherry strawberry banana

```

### Two dimensional list {#two-dimensional-list}

```php
<ul>
    <f:groupedFor each="{0: {name: 'apple', color: 'green'}, 1: {name: 'cherry', color: 'red'}, 2: {name: 'banana', color: 'yellow'}, 3: {name: 'strawberry', color: 'red'}}" as="fruitsOfThisColor" groupBy="color" groupKey="color">
        <li>
            {color} fruits:
            <ul>
                <f:for each="{fruitsOfThisColor}" as="fruit" key="label">
                    <li>{label}: {fruit.name}</li>
                </f:for>
            </ul>
        </li>
    </f:groupedFor>
</ul>

```

Output:

```php
<ul>
    <li>green fruits
        <ul>
            <li>0: apple</li>
        </ul>
    </li>
    <li>red fruits
        <ul>
            <li>1: cherry</li>
        </ul>
        <ul>
            <li>3: strawberry</li>
        </ul>
    </li>
    <li>yellow fruits
        <ul>
            <li>2: banana</li>
        </ul>
    </li>
</ul>
```

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

**Arguments**

The following arguments are available for the groupedFor ViewHelper:

-   **as**

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

    The name of the iteration variable

-   **each**

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

    The array or \\SplObjectStorage to iterated over

-   **groupBy**

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

    Group by this property

-   **groupKey**

    -   *Type:* string
    -   *Default:* 'groupKey'

    The name of the variable to store the current group
