Symfony 模板渲染语法风格

标签 symfony

我一直在问自己的一个问题:

谁能告诉我使用
@-annotationcolon-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/

相关文章:

php - Symfony2 安全 - 用户 "Ibw\UserBundle\Entity\User"没有用户提供者

symfony - 如何修改 Doctrine :migrations:diff?

symfony - 如何不转义替换文本?

php - 在带有 Doctrine2 的 Symfony2 上,Object = Entity 吗?

forms - Symfony表单如何将类添加到表单组

php - Symfony2 : What does $providerKey in UsernamePasswordToken actually do?

Symfony2 多个防火墙循环错误,其中之一

php - 如何使异常消息在 Symfony 4 用户检查器中可翻译?

symfony - 使用 symfony2 路由组件(在 symfony2 之外)

Symfony 4 - Webpack-encore 使用 FosJsRouting : Routing is not defined