N
N
NubasLol2018-09-07 10:39:18
symfony
NubasLol, 2018-09-07 10:39:18

Symfony how to call repository or controller method in twig?

Symphony needs to check in many templates if there are records in the table How can I do it so that I don’t have to pass a variable from the controller every time, but immediately in twig have access to the table

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Novikov, 2018-09-07
@NubasLol

No need to give the template access to the database. If you want to do something similar - use Twig extension
https://twig.symfony.com/doc/2.x/advanced.html#id2
https://symfony.com/doc/current/templating/twig_ex...
Create an extension class, add the necessary dependencies (repository, etc.), register a function/global variable, and the extension itself in cofigs.
And after that, use a global variable / function in any templates, which themselves under the hood will receive data from where you specify

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question