How to use their service in php templating engine in Symfony 2?

$foo = $this->get('foo');
This code works in the controller. However, if you use the php templating engine, it gives
The helper "foo" is not defined.

In services.yml written as follows:
services: foo: class: App\CoreBundle\Classes\Foo
Thank you in advance...
October 3rd 19 at 03:09
2 answers
October 3rd 19 at 03:11
so get your service in the controller and pass it to the template
I do not think that the use of serwisow from a template is a good idea. - toni commented on October 3rd 19 at 03:14
I'm not saying it's good. Just said how to do that what is conceived by the user.
And would advise all the variables that will be needed in the template to the controller and have them pass it on to the template. - kim4 commented on October 3rd 19 at 03:17
Understood. Okay, I'll be using are so true! Thanks for the tip! - webster27 commented on October 3rd 19 at 03:20
October 3rd 19 at 03:13
You need to use Twig Globals
It is only with TWIGA work? - toni commented on October 3rd 19 at 03:16

Find more questions by tags Symfony