$field->replace()
It parses any queries found in the field value.
$field->replace(array $data = [ ], string|null $fallback = ''): Kirby\Content\Field
Parameters
Name | Type | Default | Description |
---|---|---|---|
$data | array |
[ ]
|
|
$fallback | string ornull |
''
|
Fallback for tokens in the template that cannot be replaced (null to keep the original token) |
Return type
This method modifies the existing $field
object it is applied to and returns it again.
Examples
Given the field contains string templates, use this method to replace them with values:
Example text:
Text: The company behind {{ product }} and the responsible data controller for this website is the {{ company }}.
<?= $page->text()->replace(
[
'company' => 'Content Folder GmbH & Co. KG',
'product' => 'Kirby CMS'
]
);
Will result in
The company behind Kirby CMS and the responsible data controller for this website is the Content Folder GmbH & Co. KG.