Unable to find Twig template using render method in Symfony 2

好久不见. 提交于 2019-12-24 00:09:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!