Symfony cannot find the template file

php, symfony

Solution

You need to render it with the following syntax:

$this->render('AcmeBlogBundle:Blog:index.html.twig')

or with this syntax

$this->render('@BlogBundle/Blog/index.html.twig')

An Example:

$this->render('@FrontBundle/Hello/buy.html.twig) 

More information can be found on the documentation, also refering to symfonys best practices templates should be stored in `app/Ressources/views`

Problem

I have follow all the steps related to Symfony installation, and I try the examples of the Symfony book (provided by the Symfony web site). Currently I am on Controllers chapter (5) and I try the following code: ``` namespace MyBundle\FrontBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class HelloController extends Controller { public function indexAction($name, Request $request) { return $this->redirect($this->generateUrl('front_buy'), 301); } public function buyAction(Request $request) { return $this->render( 'Hello/buy.html.twig', array( 'name' => 'Nikos' ) ); } } ``` but I get the following error: ``` INFO - Matched route "front_buy" (parameters: "_controller": "MyBundle\FrontBundle\Controller\HelloController::buyAction", "_route": "front_buy") CRITICAL - Uncaught PHP Exception InvalidArgumentException: "Unable to find template "Hello/buy.html.twig"." at /var/www/projects/symfony/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 128 ``` Context: {"exception":"Object(InvalidArgumentException)"} I know is not something fancy, but I don't know how to fix the problem. My view file is under the following path : `./src/MyBundle/FrontBundle/Resources/views/Hello/buy.html.twig`.

Original source