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

69,668

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

Share:
69,668
Benji_X80
Author by

Benji_X80

Hi! www.bxnxg.com My website : Development, Webdesign, PHP, HTML5...

Updated on August 20, 2020

Comments

  • Benji_X80
    Benji_X80 over 3 years

    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!