[英]Symfony2 cannot render template inside Bundle
I have the following structure: 我有以下结构:
/src/Product/AdminBundle/Resources/views/main.twig
I am trying to render this template from controller: 我正在尝试从控制器渲染此模板:
$this->render(...);
or from routing.yml 或从routing.yml
index_page:
path: /
defaults:
_controller: FrameworkBundle:Template:template
template: ...
How can I render this from from inside the controller in the bundle? 如何从捆绑软件中的控制器内部渲染此图像? Here is what I have tried with no luck:
这是我没有运气尝试过的:
The usual path syntax is: 通常的路径语法为:
BundleName:DirectoryInView:file.html.twig
In your case, this will be: 在您的情况下,这将是:
ProductAdminBundle::main.html.twig
We use ::
, because your view is located in the root directory. 我们使用
::
,因为您的视图位于根目录中。
在尝试了每种可能的组合之后,这对我有用:
@AdminBundle/Resources/views/main.twig
Try like this: 尝试这样:
return $this->render('ProductAdminBundle:main.html.twig', []);
Where main.html.twig
is your view name (and not main.twig). 其中
main.html.twig
是您的视图名称(而不是main.twig)。
AdminBundle::main.twig does not work AdminBundle :: main.twig不起作用
rename main.twig into main.html.twig 将main.twig重命名为main.html.twig
After that AdminBundle::main.html.twig will work! 之后,AdminBundle :: main.html.twig将起作用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.