Skip to content

Kirby 3.9.8

$field->replace()

It parses any queries found in the field value.

$field->replace(array $data = [ ], ?string $fallback = ''): Kirby\Cms\Field

Parameters

Name Type Default Description
$data array [ ]
$fallback string|null '' Fallback for tokens in the template that cannot be replaced
(null to keep the original token)

Return type

Kirby\Cms\Field

Example

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.