我正在将我的项目从Symfony 2.0.22升级到2.2.0并查看一些更改,但是我对此受阻:
我想使用其 Controller 渲染 header (例如在Sf 2.0.X中),而“render” twig方法对我不起作用。他们是错误的:
An exception has been thrown during the rendering of a template ("No route found for "GET Index:header"") in "OSSiteBundle:Index:index.html.twig".
这是实际的渲染方法:
{# src/OS/SiteBundle/Resources/views/layout.html.twig #}
...
{% render "OSSiteBundle:Index:header" with {'thisid' : block('thisid'), ... } %}
我试过了 :
{{ render('OSSiteBundle:Index:header' , {'thisid' : block('thisid'), 'thistitle' : block('thistitle'), 'thisunderpageid' : block('thisunderpageid'), 'thisbackground' : block('thisbackground') }) }}
{{ include("OSSiteBundle:Index:header.html.twig", {'thisid' : block('thisid'), 'thistitle' : block('thistitle'), 'thisunderpageid' : block('thisunderpageid'), 'thisbackground' : block('thisbackground') }) }}
=>最后一项工作,但Controller没有以这种方式进行排序我什至尝试了一个带有routing.yml中路径的渲染器。
最佳答案
在Symfony> = 2.2.x中,您应该这样嵌入 Controller :
{{ render(controller('AcmeArticleBundle:Article:recentArticles', { 'max': 3 })) }}
看一下文档:
Creating and using Templates
UPGRADE-2.2
关于symfony - 如何在Symfony 2.2中使用 “render”在Twig中插入 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15221230/