-
-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Tempest version
2.11.2
PHP version
8.4
Operating system
Linux
Description
In Twig, it's possible to add - to {{ variable }}, e.g.: {{- variable -}} to remove whitespaces from a side, see Whitespace control documentation, but it conflict with {- -} syntax from DeletionInjection.
The following code:
{% props variant = 'default' %}
<twig:Button variant="{{ variant }}" {{ ...attributes }}>
{{- block(outerBlocks.content) -}}
</twig:Button>Ideally, {- and -} should not be understood as a deletion if there is a { or } preceding or following the deletion tokens.
As a current workaround, I can pass a custom Language implementation extending TwigLanguage, but which filters DeletionInjection from injections:
$language = new class extends TwigLanguage {
public function getInjections(): array
{
return array_filter(parent::getInjections(), static function (Injection $injection) {
return !$injection instanceof DeletionInjection;
});
}
};Steps to reproduce
$code = <<<EOF
{% props variant = 'default' %}
<twig:Button variant="{{ variant }}" {{ ...attributes }}>
{{- block(outerBlocks.content) -}}
</twig:Button>
EOF;
$language = 'twig';
$highlighter = new Highlighter();
$parsed = $highlighter->parse($code, $language);Metadata
Metadata
Assignees
Labels
No labels
