File tree 1 file changed +17
-4
lines changed
1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,25 @@ any related error message:
17
17
18
18
.. note ::
19
19
20
- The ``template_from_string `` function is not available by default. You
21
- must add the ``\Twig\Extension\StringLoaderExtension `` extension explicitly when
22
- creating your Twig environment::
20
+ The ``template_from_string `` function is not available by default.
21
+
22
+ On Symfony projects, you need to load it in your ``services.yaml `` file:
23
+
24
+ .. code-block :: yaml
25
+
26
+ services :
27
+ Twig\Extension\StringLoaderExtension :
28
+
29
+ or ``services.php `` file::
30
+
31
+ $services->set(\Twig\Extension\StringLoaderExtension::class);
32
+
33
+ Otherwise, add the extension explicitly on the Twig environment::
34
+
35
+ use Twig\Extension\StringLoaderExtension;
23
36
24
37
$twig = new \Twig\Environment(...);
25
- $twig->addExtension(new \Twig\Extension\ StringLoaderExtension());
38
+ $twig->addExtension(new StringLoaderExtension());
26
39
27
40
.. note ::
28
41
You can’t perform that action at this time.
0 commit comments