简体   繁体   中英

Unable to find Twig template using render method in Symfony 2

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

我认为这是因为模板“AyrshireMinisCommonBundle:Link:links.html.twig”不存在,请尝试将其更改为“AyrshireMinisCommonBundle: Default :links.html.twig”

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM