Unable to find template in Symfony 3

29,228

Solution 1

According to the Symfony 3 Docs it's better to use slashes and to not use "Bundle" word.

So, we have as example:

return $this->render('@BloggerBlog/Default/index.html.twig');

Solution 2

try to change this:

return $this->render('CoreBundle:index.html.twig');

to this:

return $this->render('CoreBundle::index.html.twig');

The difference is to use :: instead of :

Solution 3

This helped me in my case: @Core/index.html.twig

Share:
29,228

Related videos on Youtube

N.Jourdan
Author by

N.Jourdan

Updated on February 19, 2020

Comments

  • N.Jourdan
    N.Jourdan about 4 years

    I know that there are a lot of subject like that however I didn't find the solution

    I have this issue

    Unable to find template "CoreBundle:index.html.twig" (looked into: /var/www/html/MyProject/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).

    This is the architecture enter image description here This is my controller

    <?php
    
    namespace CoreBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    
    class DefaultController extends Controller
    {
        /**
         * @Route("/", name="index")
         */
        public function indexAction(Request $request)
        {
            return $this->render('CoreBundle:index.html.twig');
        }
    
        /**
         * @Route("/ma-personnalite", name="ma-personnalite")
         */
        public function mapersonnaliteAction(Request $request)
        {
            return $this->render('CoreBundle:ma_personnalite.html.twig');
        }
    
        /**
         * @Route("/cv", name="cv")
         */
        public function cvAction(Request $request)
        {
            return $this->render('CoreBundle:cv.html.twig');
        }
    
        /**
         * @Route("/scolaires", name="scolaires")
         */
        public function scolairesAction(Request $request)
        {
            return $this->render('CoreBundle:scolaires.html.twig');
        }
    
        /**
         * @Route("/extra-scolaires", name="extra-scolaires")
         */
        public function extrascolairesAction(Request $request)
        {
            return $this->render('CoreBundle:extra_scolaires.html.twig');
        }
    
        /**
         * @Route("/contact", name="contact")
         */
        public function contactAction(Request $request)
        {
            return $this->render('CoreBundle:contact.html.twig');
        }
    }
    

    This is the config.yml

    #app/config/routing.yml
    core:
        resource: "@CoreBundle/Controller/"
        type:     annotation
        prefix:   /
    

    Thanks for your time

  • N.Jourdan
    N.Jourdan almost 7 years
    Thank you very much ! How can I do to include when there is a folder ? (I want to include CoreBundle/Index/_meta.html.twig)
  • Alessandro Minoccheri
    Alessandro Minoccheri almost 7 years
    Something like this: 'CoreBundle::example\index.html.twig I think but you need to try
  • N.Jourdan
    N.Jourdan almost 7 years
    You're my heroes
  • Alessandro Minoccheri
    Alessandro Minoccheri almost 7 years
    Ahaha glad to help you!