Categories
Symfony3+Twig How to make a global variable?
Good evening. Please tell me how to implement a global variable, for example {{ tags.name }}, with the output of a specific value from the database in any template.
Answer the question
In order to leave comments, you need to log in
Make a service that can give you the data you need upon request of the desired method. And inject the service into twig. In config.yml:
twig: globals: your_service: '@your_service'
{{ your_service.someMethod() }}
Didn't find what you were looking for?
Ask a Question
731 491 924 answers to any question