lemmon
September 21, 2022, 1:29pm
1
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!
texnixe
September 21, 2022, 1:47pm
2
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
lemmon
September 22, 2022, 1:09pm
3
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 ]);