@@ -129,18 +129,34 @@ static function (ChildDefinition $definition, AsTwigComponent $attribute) {
129
129
;
130
130
131
131
$ container ->register ('ux.twig_component.twig.lexer ' , ComponentLexer::class);
132
+ if (true === $ config ['short_tags ' ]) {
133
+ $ container ->getDefinition ('ux.twig_component.twig.lexer ' )
134
+ ->addMethodCall ('enableShortTags ' );
135
+ }
132
136
133
137
$ container ->register ('ux.twig_component.twig.environment_configurator ' , TwigEnvironmentConfigurator::class)
134
138
->setDecoratedService (new Reference ('twig.configurator.environment ' ))
135
139
->setArguments ([new Reference ('ux.twig_component.twig.environment_configurator.inner ' )]);
136
140
141
+ // Currently, the ComponentLexer is not injected into the TwigEnvironmentConfigurator, but built directly in the
142
+ // code (with a new ComponentLexer($environment)).
143
+ // We cannot change this behavior without a major refactoring : environment is currently configured at runtime.
144
+ // So we add setters for our required options
145
+ // This should be improved in the future: currently, parameters of the ComponentLexer are not injectables.
146
+ if (true === $ config ['short_tags ' ]) {
147
+ $ container ->getDefinition ('ux.twig_component.twig.environment_configurator ' )
148
+ ->addMethodCall ('enabledShortTags ' );
149
+ }
150
+
137
151
$ container ->register ('ux.twig_component.command.debug ' , TwigComponentDebugCommand::class)
138
152
->setArguments ([
139
153
new Parameter ('twig.default_path ' ),
140
154
new Reference ('ux.twig_component.component_factory ' ),
141
155
new Reference ('twig ' ),
142
156
new AbstractArgument (\sprintf ('Added in %s. ' , TwigComponentPass::class)),
143
157
$ config ['anonymous_template_directory ' ],
158
+ $ config ['short_tags ' ],
159
+ $ config ['profiler ' ],
144
160
])
145
161
->addTag ('console.command ' )
146
162
;
@@ -217,6 +233,10 @@ public function getConfigTreeBuilder(): TreeBuilder
217
233
->info ('Enables the profiler for Twig Component (in debug mode) ' )
218
234
->defaultValue ('%kernel.debug% ' )
219
235
->end ()
236
+ ->booleanNode ('short_tags ' )
237
+ ->info ('Enables the short syntax for Twig Components (the <twig: prefix is optional) ' )
238
+ ->defaultValue (false )
239
+ ->end ()
220
240
->scalarNode ('controllers_json ' )
221
241
->setDeprecated ('symfony/ux-twig-component ' , '2.18 ' , 'The "twig_component.controllers_json" config option is deprecated, and will be removed in 3.0. ' )
222
242
->defaultNull ()
0 commit comments