StartsWith ViewHelper <f:startsWith>
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.