StartsWith ViewHelper <f:startsWith>
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 instead.
StartsWith ViewHelper checks if the subject string starts with a specified string. This ViewHelper implements an if/else condition.
Examples
Render the body if "myString" starts with "Hello"
<f:variable name="myString" value="Hello, World!" />
<f:startsWith search="Hello" subject="{myString}">This will be rendered if variable "myString" starts with "Hello"</f:startsWith>
Copied!
Output:
This will be rendered if variable "myString" starts with "Hello"
Copied!
A more complex example with inline notation
<f:variable name="condition" value="{false}" />
<f:variable name="myString" value="Hello, World!" />
<f:if condition="{condition} || {f:startsWith(search: 'Hello', subject: myString)}">
It Works!
</f:if>
Copied!
Output:
It Works!
Copied!
Go to the source code of this ViewHelper: StartsWithViewHelper.php (GitHub).
Arguments
The following arguments are available for the startsWith ViewHelper:
else
-
- Type
- mixed
Value to be returned if the condition if not met.
search
-
- Type
- string
- Required
- 1
String to search in subject at the beginning
subject
-
- Type
- string
- Required
- 1
String to search in
then
-
- Type
- mixed
Value to be returned if the condition if met.