How to save double quotes in a branch?

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!

+7
json javascript php symfony twig
source share
1 answer

It looks like you have auto-escaping. (e: which is good)

Have you tried {{ arr|raw }} ?

+12
source share

All Articles