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

1

34

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!

Sardonyx answered 5/3, 2013 at 10:17 Comment(0)
Y
87

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

Yezd answered 5/3, 2013 at 10:24 Comment(1)
Thanks that it! I was going to write the same thing too! The documentation upgrade : github.com/symfony/symfony/blob/master/…Sardonyx

© 2022 - 2024 — McMap. All rights reserved.