@@ -158,17 +158,16 @@ Twig Extension & Autoconfiguration
158
158
159
159
Thanks to Symfony's service handling, you can *extend * Symfony in many ways, like
160
160
by creating an event subscriber or a security voter for complex authorization
161
- rules. Let's add a new filter to Twig called ``greet ``. How? Create a class
162
- that extends `` AbstractExtension `` ::
161
+ rules. Let's add a new filter to Twig called ``greet ``. How? Create a simple class
162
+ with your logic ::
163
163
164
164
// src/Twig/GreetExtension.php
165
165
namespace App\Twig;
166
166
167
167
use App\GreetingGenerator;
168
168
use Twig\Attribute\AsTwigFilter;
169
- use Twig\Extension\AbstractExtension;
170
169
171
- class GreetExtension extends AbstractExtension
170
+ class GreetExtension
172
171
{
173
172
public function __construct(
174
173
private GreetingGenerator $greetingGenerator,
@@ -191,8 +190,8 @@ After creating just *one* file, you can use this immediately:
191
190
{# templates/default/index.html.twig #}
192
191
{# Will print something like "Hey Symfony!" #}
193
192
<h1>{{ name|greet }}</h1>
194
-
195
- How does this work? Symfony notices that your class extends `` AbstractExtension ``
193
+
194
+ How does this work? Symfony notices that your class uses Twig attributes
196
195
and so *automatically * registers it as a Twig extension. This is called autoconfiguration,
197
196
and it works for *many * many things. Create a class and then extend a base class
198
197
(or implement an interface). Symfony takes care of the rest.
0 commit comments