How to insert a Controller in Twig with "render" in Symfony 2.2?

Benji_X80 picture Benji_X80 · Mar 5, 2013 · Viewed 69.1k times · Source

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

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 :

An exception has been thrown during the rendering of a template ("No route found for "GET Index:header"") in "OSSiteBundle:Index:index.html.twig".

Here is the actual render method :

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

...

{% render "OSSiteBundle:Index:header" with {'thisid' : block('thisid'), ... } %}

I tried :

{{ 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

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

Answer

Juan Sosa picture Juan Sosa · Mar 5, 2013

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

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

Take a look at the documentation:

Creating and using Templates

UPGRADE-2.2