Closed
Description
Symfony version(s) affected
6.2.*
Description
An issue occurs in
{{ react_component('LoginComponent',{
site: site|serialize('json', { groups: 'site:read'})
}) }}>
it does not work as serialize return a string {'name':'value'} and it get escaped again in react_controller.
this lead to error when using it in react , site.name for example.
this work fine:
{{ react_component('LoginComponent',{
site: {'name':'value'}
}) }}>
because its an array and it get not escaped twice .
How to reproduce
{{ react_component('LoginComponent',{
site: site|serialize('json', { groups: 'site:read'})
}) }}>
Possible Solution
{{ react_component('LoginComponent',{
site: site|serialize('json', { groups: 'site:read'})|json_decode
}) }}
the json_decode si a custom twig filter that turn the json string back to array .
class JsonDecode extends AbstractExtension
{
public function getFilters()
{
return [
new TwigFilter('json_decode', [$this, 'jsonDecode']),
];
}
public function jsonDecode($string)
{
return json_decode($string);
}
}
Additional Context
No response