1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 13:16:45 +02:00

feat(directives): add ability to customize tags for expressions directive

This commit is contained in:
Awilum
2022-05-27 19:55:09 +03:00
parent e987c1dea4
commit 045ef17372
3 changed files with 9 additions and 1 deletions

View File

@@ -27,10 +27,14 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void {
return;
}
$selfQuote = fn ($text) => preg_replace('/(.)/us', '\\\\$0', $text);
$openingTag = registry()->get('flextype.settings.entries.directives.expressions.opening_tag');
$closingTag = registry()->get('flextype.settings.entries.directives.expressions.closing_tag');
$field = entries()->registry()->get('methods.fetch.field');
if (is_string($field['value'])) {
$field['value'] = preg_replace_callback('/\[\[ (.*?) \]\]/s', function($matches) {
$field['value'] = preg_replace_callback('/' . $selfQuote($openingTag) . ' (.*?) ' . $selfQuote($closingTag) . '/s', function($matches) {
return expression()->evaluate($matches[1]);
}, $field['value']);
}

View File

@@ -81,6 +81,8 @@ entries:
enabled: true
enabled_globally: true
path: "/src/flextype/core/Entries/Directives/ExpressionsDirective.php"
opening_tag: "[["
closing_tag: "]]"
shortcodes:
enabled: true
enabled_globally: true

View File

@@ -77,6 +77,8 @@ entries:
enabled: true
enabled_globally: true
path: "/src/flextype/core/Entries/Directives/ExpressionsDirective.php"
opening_tag: "[["
closing_tag: "]]"
shortcodes:
enabled: true
enabled_globally: true