Symfony2 @Template in the controller

I use annotation routing and this is my controller:

/** * @Route("/", name="_index") * @Template() */ 

I understand the routes, but can someone explain what @Template () does there, and how can I use it? I could not find documentation about this.

Thanks...

+4
source share
2 answers

The @Template annotation associates a controller with a template name:

More information here: http://symfony.com/doc/2.0/bundles/SensioFrameworkExtraBundle/annotations/view.html

+7
source

In addition to this answer (by the way, right). You must add the suffix ".html.twig" if you use the TWIG mechanism to render templates.

Your image should look like this:

 /** * @Template("MyOwnBundle:Default:myOwnView.html.twig") */ public function showAction() { ... bla bla bla ... more bla bla } 

In this case, you force showAction () to use a custom template. If @Template () is empty, your showAction () will search for the appropriate template by convention.

Hope this helps. If not, it will only β€œdecorate” a little more answer.

+1
source

Source: https://habr.com/ru/post/1387714/


All Articles