Reputation: 61
I'm having some trouble runnning Symfony. In fact, it can't find the default twig template. I didn't touch the code at all, juste generated my bundle and trying to access /web/app_dev.php.
My template is in
/src/OC/PlatformBundle/Resources/views/Default/index.html.twig.
Symfony looked into these locations, but not where my template actually is.
/app/Resources/views
/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form
And the DefaultController.php indexAction() looks ok :
public function indexAction(){
return $this->render("OCPlatform:Default:index.html.twig");
}
If any of you have ever faced this kind of issue or have any idea where the problem comes from, I thank you in advance for your help.
Arthur
Upvotes: 1
Views: 8961
Reputation: 79
In symfony 4 use this :
return $this->render("@Platform/Default/index.html.twig");
Upvotes: 0
Reputation: 496
Referencing Templates in a Bundle¶
If you need to refer to a template that lives in a bundle, Symfony uses the
Twig namespaced syntax (@BundleName/directory/filename.html.twig).
This allows for several types of templates, each which lives in a specific location:
@AcmeBlog/Blog/index.html.twig: <br>This syntax is used to specify a template for a specific page. The three parts of the string, each separated by a slash (/), mean the following:<br>
@AcmeBlog: is the bundle name without the Bundle suffix. This template lives in the AcmeBlogBundle (e.g. src/Acme/BlogBundle);<br>
Blog: (directory) indicates that the template lives inside the Blog subdirectory of Resources/views/;<br>
index.html.twig: (filename) the actual name of the file is index.html.twig.
Upvotes: 0
Reputation: 762
This worked for me:
return $this->render('@HomeBundle/Default/index.html.twig');
Hope it hope :)
Upvotes: 0
Reputation: 346
If you want to keep using the 'OCPlatform:Default:index.html.twig' format for templates then edit your app/config/config.yml file:
#app/config/config.yml framework: templating: engines: ['twig']
This fixed my problem. You can check this link Symfony 3.4 Use view inside my bundle
Upvotes: 1
Reputation: 29
I've same problem and i resolve it with this route :
public function indexAction(){
return $this->render("@OCPlatform/Default/index.html.twig");
}
Edit ":" with "/" and it work. Maybe can help other developper
Upvotes: 2
Reputation: 799
Following the docs(Symfony >=3.4) you should write the path to the template in the controller like this:
public function indexAction(){
return $this->render("@OCPlatform:Default:index.html.twig");
}
Upvotes: 0