I have a json array that I pass to the twig template, but double quotes in the array cause problems, my json array looks like this:
$arr = json_encode(array("a", "b")); // which prints out ["a", "b"]
in the branch template, I print it like this:
attrs: {{ arr }}
I expect it to be attrs: ["a", "b"] , however, what gets the output is attrs: ["a", "b"] , I tried attrs: {{ arr|e('js') }} but no luck, my js lib just says there are some unrecognized characters. So, how do I think attrs: ["a", "b"] ?
Many thanks!
json javascript php symfony twig
Michael
source share