4

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...

2 Answers 2

7

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that was what I needed to understand it. I dont know why in google it did not come up as a result.
1

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.

1 Comment

yes, for some reason usual template name: MyOwnBundle:Default:myOwnView doesn't work, it requires .html.twig extension

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.