Sometimes we may need to inject the same variable in all the Twig templates. It can be done on each controller by passing a variable to template. However, it is not a good solution. This tutorial shows how to define global variables for Twig templates in Symfony 7 application.
Global variables for Twig templates can be defined using globals
option under the twig
key:
twig:
globals:
tracking_id: 'XXXXX-YYYYY-ZZZZZ'
In our case, the variable tracking_id
will be injected automatically into all the Twig templates.
{{ tracking_id }}
Leave a Comment
Cancel reply