2
votes

Updating deprecated code and i have following problem with render tag

> {% render url('_internal_main_navigation', {}) %}

transaltes to

{{ render(controller('MyBundle::menu', {})) }}

Twig does this thing where it appends "Controller" and "Action" to the specified route so That should call MyBundle/Controller/Controller->menuAction() but apparently the Controller class is supposed to have some sort of prefix like "MyController" so the twig route can be specified like 'Bundle:My:menu' otherwise i get

Class "MyBundle" noes not exist

Can i make it work without prefixing the controller?

1
what is the problem with telling the controller ? if you don't put it, how the twig render is supposed to find which one it have to call ?t-n-y
it should use Controller.php if i specify nothing since Controller is appended to class part of "bundle:class:action" But it does not. I have A Class named just that - Controller.php in which the specified route is defined for menuAction function.Martin

1 Answers

1
votes

I'd recommend to use render_esi() which supports routes via url() by name aswell and you're set for ESI in the future.

When using the default render() function (or setting the renderer to inline), Symfony merges the included page content into the main one before sending the response to the client. But if you use the esi renderer (i.e. call render_esi()) and if Symfony detects that it's talking to a gateway cache that supports ESI, it generates an ESI include tag. But if there is no gateway cache or if it does not support ESI, Symfony will just merge the included page content within the main one as it would have done if you had used render().

See Using ESI in Symfony

The following syntax will work in your case:

{{ render_esi(url('_internal_main_navigation', {})) }}

If you'd like to render by controller-name, you could turn your controller into a service and refer to it by the name of the service (i.e. mybundle_controller):

{{ render_esi(controller('mybundle_controller:menuAction', {})) }}