Symfony Twig {{render}} handling passed arguments

2019-08-02 08:50发布

问题:

Over a template I do a render method:

{{ render(controller('AppBundle:Widgets:myCapsWidget'),{'somestring':someString})  }}

Over the controller I have the following method:

public function myCapsWidgetAction($somestring)
{
  return new Response(strtoupper($somestring));
}

I also looked over theese links:

  • symfony twig render controller argument array
  • https://knpuniversity.com/screencast/symfony2-ep3/render-controller

But still cannot find any light to my path.

回答1:

If I read the first link you gave us, you should use:

{{ render(controller('AppBundle:Widgets:myCapsWidget',{'somestring':someString}))  }}