Symfony 4 - Not rendering Twig Template

牧云@^-^@ 提交于 2020-01-23 08:56:47

问题


When trying to render a Twig Template within a Symfony 4 project I'm getting an error. I don't know which is the problem. This is the code generating the error:

return $this->render('templates/imagenes/index.html.twig');

And this is the error I'm getting:

LogicException You can not use the "render" method if the Templating Component or the Twig Bundle are not available.

Should I install Twig via composer apart Symfony itself?


回答1:


Thanks @gogaz Installing twig did the trick.

composer require twig



回答2:


and you should not need the templates directory, so just 'imagenes/index.html.twig'




回答3:


 return $this->render('templates/imagenes/index.html.twig');

Create the project using this command

composer create-project symfony/skeleton-website project_name

No need to install twig,etc




回答4:


A guy named Simon Wald-burger mentioned in the lesson's comments that installing "debug" fixed the issue (it fixed it for me). The instruction was in the next lesson.

composer require debug --dev

iiirxs is also correct, to output dump in twig file, do

{{ dump(variable) }}


来源:https://stackoverflow.com/questions/47743256/symfony-4-not-rendering-twig-template

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