Parsing query data within the field content

Hi,

I have regular text field containing:

Copyright (date: year) {{site.name}}

When applying KirbyText I receive content with KirbyTags processed, as expected:

Copyright 2022 {{site.name}}

Is there built-in functionality to parse the Queries and return appropriate results in same fashion as KirbyTags are parsed?

Thanks!

No, that’s not possible.

If placeholders are not enough for your use case(see The power of placeholders | Kirby CMS) and you really need query language, you could use a kirbytag hook that searches for strings in double curly braces and pass the argument to a Query object: new Query() | Kirby CMS

Thanks for the hints. I’ve put together a little utility to make it work:

Kirby::plugin('lemmon/fieldquery', [
    'fieldMethods' => [
        'applyQueries' => function ($field) {
            $field->value = preg_replace_callback('/{{([^}]+)}}/', function ($x) {
                return Str::query($x[1], [
                    'kirby' => kirby(),
                    'site'  => site(),
                    'page'  => page()
                ]);
            }, $field->value);
            return $field;
        },
    ],
]);

It would be cool though if KirbyText allowed for such functionality as a built-in option (I understand it is not desired everywhere).

$page->mytextfield->kirbytext([ 'queries' => true ]);