Skip to content

Commit 62cf7ab

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Global variable in TwigConfig should be passed by service function
2 parents 85b3bac + 574b9be commit 62cf7ab

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

templating/global_variables.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,20 @@ the ``@`` character, which is the usual syntax to
9292
9393
<twig:config>
9494
<!-- ... -->
95-
<twig:global key="uuid">@App\Generator\UuidGenerator</twig:global>
95+
<twig:global key="foo" id="App\Generator\UuidGenerator" type="service"/>
9696
</twig:config>
9797
</container>
9898
9999
.. code-block:: php
100100
101101
// config/packages/twig.php
102102
use Symfony\Config\TwigConfig;
103+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
103104
104105
return static function (TwigConfig $twig) {
105106
// ...
106107
107-
$twig->global('uuid')->value('@App\Generator\UuidGenerator');
108+
$twig->global('uuid')->value(service('App\Generator\UuidGenerator'));
108109
};
109110
110111
Now you can use the ``uuid`` variable in any Twig template to access to the

0 commit comments

Comments
 (0)