Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 @Template in Controller

Tags:

php

symfony

I am using routing by annotations and this is what my controller has:

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

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

Thanks...

like image 447
TroodoN-Mike Avatar asked Feb 23 '23 01:02

TroodoN-Mike


2 Answers

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

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

like image 86
Flukey Avatar answered Mar 04 '23 19:03

Flukey


In addition to this answer (btw, is correct). You should add the suffix ".html.twig" in case you're using the TWIG engine to render the templates.

Your should look like this

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

In this case, you're forcing the showAction() to use a custom template. If the @Template() is empty, your showAction() will looking for the associated template by convention.

Hope this helps.. if not, only "decorates" a little bit more the answer.

like image 23
DavidSilveira Avatar answered Mar 04 '23 20:03

DavidSilveira