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

# Contains ViewHelper `<f:contains>` {#typo3fluid-fluid-contains}

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

The ContainsViewHelper checks if a provided string or array contains
the specified value. Depending on the input, this mimicks PHP's
`in_array()` or `str_contains()`.

## Examples {#examples}

### Check value in array {#check-value-in-array}

```php
<f:variable name="myArray" value="{0: 'Hello', 1: 'World'}" />

<f:contains value="Hello" subject="{myArray}">
    It Works!
</f:contains>

```

Output:

```php
It Works!

```

### Check value in string {#check-value-in-string}

```php
<f:variable name="myString" value="Hello, World!" />

<f:contains value="Wo" subject="{myString}">
    It Works!
</f:contains>

```

Output:

```php
It Works!

```

### A more complex example with inline notation {#a-more-complex-example-with-inline-notation}

```php
<f:variable name="myString" value="Hello, World!" />

<f:if condition="{someCondition} || {f:contains(value: 'Wo', subject: myString)}">
    It Works!
</f:if>

```

Output:

```php
It Works!
```

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

**Arguments**

The following arguments are available for the contains ViewHelper:

-   **else**

    -   *Type:* mixed

    Value to be returned if the condition if not met.

-   **subject**

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

    The string or array that might contain the value (haystack)

-   **then**

    -   *Type:* mixed

    Value to be returned if the condition if met.

-   **value**

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

    The value to check for (needle)
