我一直在问自己的一个问题:
谁能告诉我使用 @-annotation
或 colon-style
渲染模板是否有区别:
@Acme/AcmeBundle/Default/index.html.twig
Acme:AcmeBundle:Default:index.html.twig
如果有区别的话是什么,
如果不是,哪一个是较新/合适的并且应该相应地使用?
最佳答案
命名空间模板和传统模板都将在 View 中按预期工作,但在 Controller 中不起作用。请查看here
// namespaced templates will no longer work in controllers
$this->render('@App/Default/index.html.twig');
// you must use the traditional template notation
$this->render('AppBundle:Default:index.html.twig');
{# inside a Twig template, namespaced templates work as expected #}
{{ include('@App/Default/index.html.twig') }}
{# traditional template notation will also work #}
{{ include('AppBundle:Default:index.html.twig') }}
命名空间语法更快。
请引用this了解更多信息
关于Symfony 模板渲染语法风格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36977615/