Replace ViewHelper <f:replace>

The ReplaceViewHelper replaces one or multiple strings with other strings. This ViewHelper mimicks PHP's str_replace() function. However, it's also possible to provide replace pairs as associative array via the "replace" argument.

Examples

Replace a single string

<f:replace value="Hello World" search="World" replace="Fluid" />
Copied!
Hello Fluid
Copied!

Replace multiple strings

<f:replace value="Hello World" search="{0: 'World', 1: 'Hello'}" replace="{0: 'Fluid', 1: 'Hi'}" />
Copied!
Hi Fluid
Copied!

Replace multiple strings using associative array

<f:replace value="Hello World" replace="{'World': 'Fluid', 'Hello': 'Hi'}" />
Copied!
Hi Fluid
Copied!

Source code

Go to the source code of this ViewHelper: ReplaceViewHelper.php (GitHub).

Arguments

The following arguments are available for <f:replace>:

Name display Type Default
string
mixed
mixed
value
Type
string
Type
mixed
replace
Type
mixed
Required

true