问题
I am experiencing an issue trying to reference a particular Twig template. I am using the render
method that is part of the SF2 main controller, but I clearly not referencing/using it correctly.
This is my directory/file structure:
/src
/AyrshireMinis
/CommonBundle
/Controller
DefaultController.php
/Entity
Link.php
/Resources
/views
/Default
links.html.twig
and this is the method called by the router in DefaultContoller.php
:
/**
* @Route("/links", name="ayrshireminis_links")
* @Template()
*/
public function linksAction()
{
$links = $this->getDoctrine()->getRepository('AyrshireMinisCommonBundle:Link')->findAll();
return $this->render('AyrshireMinisCommonBundle:Link:links.html.twig', array('links' => $links));
}
But this is the error I get:
Unable to find template "AyrshireMinisCommonBundle:Link:links.html.twig".
回答1:
I think it's because the template "AyrshireMinisCommonBundle:Link:links.html.twig" does not exist, try changing it to "AyrshireMinisCommonBundle:Default:links.html.twig"
回答2:
I had exactly the same problem with the same directory structure. The equivalent of 'AyrshireMinisCommonBundle:Default:links.html.twig'
didn't work (meaning that the directory still could not be found). It worked when I changed it to 'Default/links.html.twig'
(Using Symfony 2.3 and PHP 5.3)
来源:https://stackoverflow.com/questions/23834766/unable-to-find-twig-template-using-render-method-in-symfony-2