4
votes

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?

4
yes, you shouldgogaz

4 Answers

7
votes

Thanks @gogaz Installing twig did the trick.

composer require twig
1
votes

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

0
votes
 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

0
votes

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) }}