Skip to content

Kirby 4.5.0

$field->replace()

It parses any queries found in the field value.

$field->replace(array $data = [ ], ?string $fallback = ''): Kirby\Content\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\Content\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.