首页 文章

Symfony:渲染块时出错 - 无法找到模板

提问于
浏览
1

我正在使用Sonata的块捆绑和Symfony 3.3来开发应用程序 . 我已配置了阻止服务来显示YouTube视频 .

该服务包括以下代码:

$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);

当我在笔记本电脑上使用该服务时,它运行良好 . 当我转移到另一个环境时,视频不再显示,我收到以下错误:

[2018-04-05 11:24:23] app.ERROR:[cms :: renderBlock] block.id = 13 - 渲染块时出错 - 无法找到模板“AppBundle:Components:videoElement.html.twig”(查看:/ srv / htdocs / vgms-core / app / Resources / views,/ srv / htdocs / vgms-core / vendor / symfony / symfony / src / Symfony / Bridge / Twig / Resources / views / Form,/ srv / htdocs中/ vgms核心/供应商/ knplabs / KNP-菜单/ src目录/ KNP /菜单/资源/视图) . {“exception”:“[object](InvalidArgumentException(code:0):无法找到模板\”AppBundle:Components:videoElement.html.twig \“(查看:/ 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):无法找到template \“AppBundle:Components:videoElement.html.twig \”(查看:/ 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)“} []

模板存在并存在于 src/AppBundle/Resources/views/components/videoElement.html.twig 中 .

如何明确告诉Symfony在哪里查找此模板?

1 回答

  • 1

    Referencing Templates in a Bundle (Symfony 3.3 version)中所示,您可以使用Twig语法 @BundleName/directory/filename.html.twig 指定特定包模板的位置 .

    默认情况下,特定的包模板存储在 BundleName/Resources/views 文件夹中,可以使用 @App/videoElement.html.twig 进行引用,因此在您的情况下,您只需要使用 @App/components/videoElement.html.twig 指示添加的 components 文件夹 .

相关问题