Skip to content

Kirby 5.0.4

Str::template()

Replaces placeholders in string with values from the data array

Str::template(string|null $string, array $data = [ ], array $options = [ ]): string

Parameters

Name Type Default Description
$string stringornull no default value The string with placeholders
$data array [ ] Associative array with placeholders as
keys and replacements as values.
Supports query syntax.
$options array [ ] An options array that contains:
- fallback: if a token does not have any matches
- callback: to be able to handle each matching result
- start: start placeholder
- end: end placeholder

Return type

string

The filled-in string

Parent class

Kirby\Toolkit\Str

Examples

echo Str::template('From {{ b }} to {{ a }}', ['a' => 'there', 'b' => 'here']);
// output: From here to there