symfony - 如何在Symfony 2.2中使用 “render”在Twig中插入 Controller ?

标签 symfony twig symfony-2.2

我正在将我的项目从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/

相关文章:

symfony - 使用 Doctrine2 和 QueryBuilder 聚合 SUM

arrays - 如何在 Twig 模板中设置数组值

php - 如何在 PHP 中实现多层架构

symfony - 如何在 Twig 中将字符串转换为数组

php - 我如何在 Twig 日期过滤器中使用时区?

symfony - SonataAdminBundle : display non crud (statistics)

php - Doctrine Join 表以获得相同的 ID

php - symfony的测试和浏览器有什么区别

php - Assets 中的 Twig 连接

symfony - Service(使用服务工厂)返回不同类型的对象