Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to keep double quotes in twig?

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!

like image 252
Michael Avatar asked Jun 07 '14 15:06

Michael


1 Answers

Sounds like you have auto-escaping on. (e: which is a good thing)

Have you tried {{ arr|raw }} ?

like image 102
Collin Grady Avatar answered Sep 24 '22 00:09

Collin Grady