Search code examples
phpsymfonytwigsymfony-3.3

Symfony Twig {{render}} handling passed arguments: Cannot get a different value


Over a template I do a render method:

 {% set someString = "non-default" %}

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

Over the controller I have the following method:

public function myCapsWidgetAction()
{
  //@todo: access the passing parameter
}

My problem is how can I access the somestring parameter? I tried to do

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

Then via xdebug I noticed that the passed parameter was default instead of non-default.

I also looked over theese links:

But still no light in my path.


Solution

  • According to Symfony Twig {{render}} handling passed arguments

    You should render the widget like:

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

    Look on how the argument are being passed over the controller method