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

查看:15
本文介绍了如何使用“渲染"在 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 :

我想渲染(如在 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 :

模板渲染过程中抛出异常(No为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";with {'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') }) }}

=>最后一个工作但控制器没有以这种方式收集

=> 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天全站免登陆