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

# Switch ViewHelper `<f:switch>` {#typo3fluid-fluid-switch}

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

Switch ViewHelper which can be used to render content depending on a value or expression.
Implements what a basic PHP `switch()` does.

An optional default case can be specified which is rendered if none of the
`case` conditions matches.

Using this ViewHelper can be a sign of weak architecture. If you end up using it extensively
you might want to consider restructuring your controllers/actions and/or use partials and sections.
E.g. the above example could be achieved with `<f:render partial="title.{person.gender}" />`
and the partials "title.male.html", "title.female.html", ...
Depending on the scenario this can be easier to extend and possibly contains less duplication.

## Examples {#examples}

### Simple Switch statement {#simple-switch-statement}

```php
<f:switch expression="{person.gender}">
    <f:case value="male">Mr.</f:case>
    <f:case value="female">Mrs.</f:case>
    <f:defaultCase>Mr. / Mrs.</f:defaultCase>
</f:switch>

```

Output:

```php
"Mr.", "Mrs." or "Mr. / Mrs." (depending on the value of {person.gender})
```

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

**Arguments**

The following arguments are available for the switch ViewHelper:

-   **expression**

    -   *Type:* mixed
    -   *Required:* true

    Expression to switch
