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:
@@ -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']);
|
||||
}
|
||||
|
@@ -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
|
||||
|
2
tests/fixtures/settings/settings.yaml
vendored
2
tests/fixtures/settings/settings.yaml
vendored
@@ -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
|
||||
|
Reference in New Issue
Block a user