Contains ViewHelper <f:contains>
The ContainsViewHelper checks if a provided string or array contains
the specified value. Depending on the input, this mimicks PHP's
in_ or
str_.
Examples
Check value in array
<f:variable name="myArray" value="{0: 'Hello', 1: 'World'}" />
<f:contains value="Hello" subject="{myArray}">
It Works!
</f:contains>
Copied!
Output:
It Works!
Copied!
Check value in string
<f:variable name="myString" value="Hello, World!" />
<f:contains value="Wo" subject="{myString}">
It Works!
</f:contains>
Copied!
Output:
It Works!
Copied!
A more complex example with inline notation
<f:variable name="myString" value="Hello, World!" />
<f:if condition="{someCondition} || {f:contains(value: 'Wo', subject: myString)}">
It Works!
</f:if>
Copied!
Output:
It Works!
Copied!
Go to the source code of this ViewHelper: ContainsViewHelper.php (GitHub).
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
- 1
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
- 1
The value to check for (needle)