I have a json array that I pass to the twig template, but the double quotes in the array have been causing trouble, my json array is like this:
$arr = json_encode(array("a", "b")); // which prints out ["a", "b"]
in twig template, I print it out like this:
attrs: {{ arr }}
I expect it to be attrs: ["a", "b"], however, what gets output is attrs: ["a", "b"], I tried attrs: {{ arr|e('js') }}, but no luck, my js lib just says there are some unrecognised characters. So how do I get intended attrs: ["a", "b"]?
Many thanks!
Sounds like you have auto-escaping on. (e: which is a good thing)
Have you tried {{ arr|raw }} ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With