KEIII KEIII - 1 month ago 5x
Twig Question

How to insert a Controller in Twig with “render” in Silex

Should it work in Silex with symfony/twig-bridge ?

{{ render(controller('MyController')) }}

Now I have message like this:

Twig_Error_Syntax: The function "controller" does not exist in "...


I've found this working:

{{ render(controller('services.controller:action', {[params]}) }}

And you can define the controller as a service:

$app['services.controller'] = function() use ($dependecy1, .., $dependencyN){
    return new \\PathToYourControllerClass($dependecy1, .., $dependencyN);