The simplest solution is to embed the controllers from your templates / layouts. But be careful that subqueries are expensive and can significantly affect performance. If at some point you notice that the version of your application is slow as hell, then know that the reason is probably several subqueries for each request.
The next solution is Twig extensions . In most cases, you will need functions . You can call it like this:
{{ user_info(user) }}
At first I started by embedding the controllers, but my version of dev reached the point where most of the pages on my timing site in 30 seconds. At first I did not know the reason, but as soon as I found out, I replaced all the subtasks with Twig extensions. Since then, productivity has returned to normal.
Elnur abdurrakhimov
source share