如何使用“渲染"在Twig中插入控制器?在Symfony 2.2中? [英] How to insert a Controller in Twig with "render" in Symfony 2.2?

查看:112
本文介绍了如何使用“渲染"在Twig中插入控制器?在Symfony 2.2中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的项目从Symfony 2.0.22升级到2.2.0,并查看一些更改,但是我对此受阻:

I'm upgrading my project from Symfony 2.0.22 to 2.2.0 and review somes changes, but i'm blocked on this :

我想使用其控制器和"render"控件渲染标头(如在Sf 2.0.X中).细枝法对我不起作用.他们是错误:

I would like to render (like in Sf 2.0.X) a header with their controller and the "render" twig method don't work for me. Their is the error :

在呈现模板的过程中引发了异常(否 在中找到"GET Index:header"的路由 "OSSiteBundle:Index:index.html.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#}

{# src/OS/SiteBundle/Resources/views/layout.html.twig #}

...

{%渲染"OSSiteBundle:Index:header"与{'thisid':block('thisid'),...}%}

{% 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没有以这种方式收拾

=> The last one work but the Controller isn't colled in this way

我什至尝试了一个在routing.yml中带有路径的渲染...我没有其他想法可以帮助我!

I tried even a render with a path in routing.yml... I have no other idea help me please!

推荐答案

在Symfony> = 2.2.x中,您应该这样嵌入控制器:

In Symfony >= 2.2.x you should embed your controller like this:

{{ render(controller('AcmeArticleBundle:Article:recentArticles', { 'max': 3 })) }}

看一下文档:

创建和使用模板

UPGRADE-2.2

这篇关于如何使用“渲染"在Twig中插入控制器?在Symfony 2.2中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆