When I updated from Symfony 3.4 to Symfony 4 and displayed the system with a browser, the following error appeared.
Changing the views directory is a lot of work and I don’t want to do it as much as possible. Is there any good way?
Error Code
Unable to find template "AhiSpAdminBundle:Security:login.html.twig" (looked into: /home/vagrant/Symfony/src/Sp/AppBundle/Resources/views, /home/vagrant/Symfony/templates, /home/vagrant/Symfony/vendor/symfony/twig-bridge/Resources/views/Form).
Code
framework.yaml
framework: templating: engines: ['twig']
twig.yaml
twig: paths: ['%kernel.project_dir%/src/App/AppBundle/Resources/views'] debug: '%kernel.debug%' strict_variables: '%kernel.debug%'
SecurityController.php
/** * @Route("/login") * @Template("SpAppBundle:Security:login.html.twig") */ public function loginAction(Request $request) {
Version
Symfony 4.0
PHP 7.3
twig/twig 2.14
twig/templating 4.0
sensio/framework-extra-bundle 5.2.4
Advertisement
Answer
Setting the path to twig.yaml and the accompanying changes worked.
twig.yaml
twig: paths: '%kernel.project_dir%/src/Sp/AppBundle/Resources/views': SpApp
Controller
/** * @Route("/login") * @Template("@SpApp/Security/login.html.twig") */ public function loginAction(Request $request) {
~.html.twig
{% extends '@SpApp/layout.html.twig' %}