@@ -158,17 +158,16 @@ Twig Extension & Autoconfiguration
158158
159159Thanks to Symfony's service handling, you can *extend * Symfony in many ways, like
160160by 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 ::
163163
164164 // src/Twig/GreetExtension.php
165165 namespace App\Twig;
166166
167167 use App\GreetingGenerator;
168168 use Twig\Attribute\AsTwigFilter;
169- use Twig\Extension\AbstractExtension;
170169
171- class GreetExtension extends AbstractExtension
170+ class GreetExtension
172171 {
173172 public function __construct(
174173 private GreetingGenerator $greetingGenerator,
@@ -191,8 +190,8 @@ After creating just *one* file, you can use this immediately:
191190 {# templates/default/index.html.twig #}
192191 {# Will print something like "Hey Symfony!" #}
193192 <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
196195and so *automatically * registers it as a Twig extension. This is called autoconfiguration,
197196and it works for *many * many things. Create a class and then extend a base class
198197(or implement an interface). Symfony takes care of the rest.
0 commit comments