I am using Sonata's block bundle and Symfony 3.3 to develop an application. I have configured a block service for displaying YouTube videos.
The service includes the following code:
$blockContext->setSetting('template', 'AppBundle:Components:videoElement.html.twig');
return $this->renderResponse($blockContext->getTemplate(), array(
'block' => $block,
'settings' => $settings,
'media' => $media,
'framehtml' => $frameHtml,
'provider_reference' => $providerReference,
), $response);
When I use the service on my laptop, it works well. When I shift to another environment, videos no longer display, and I get the following error:
[2018-04-05 11:24:23] app.ERROR: [cms::renderBlock] block.id=13 - error while rendering block - Unable to find template "AppBundle:Components:videoElement.html.twig" (looked into: /srv/htdocs/vgms-core/app/Resources/views, /srv/htdocs/vgms-core/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form, /srv/htdocs/vgms-core/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views). {"exception":"[object] (InvalidArgumentException(code: 0): Unable to find template \"AppBundle:Components:videoElement.html.twig\" (looked into: /srv/htdocs/vgms-core/app/Resources/views, /srv/htdocs/vgms-core/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form, /srv/htdocs/vgms-core/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views). at /srv/htdocs/vgms-core/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php:127, Twig_Error_Loader(code: 0): Unable to find template \"AppBundle:Components:videoElement.html.twig\" (looked into: /srv/htdocs/vgms-core/app/Resources/views, /srv/htdocs/vgms-core/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form, /srv/htdocs/vgms-core/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views). at /srv/htdocs/vgms-core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php:232)"} []
The template exists and lives in
src/AppBundle/Resources/views/components/videoElement.html.twig
.
How can I explicitly tell Symfony where to look for this template?
AppBundle
orapp/Resources/views
? – Imanali Mamadiev@App/components/videoElement.html.twig
which did the trick. If you want to expand this into an answer, I will mark it as the accepted one. – Patrick