I have a php variable which contain json, I use json_encode to transform an array to json.
If I print my var I have:
["L","M","M","J","V","S","D"] But if I use my var in js I have:
["L","M","M","J","V","S","D"] and I can't parse because I have an error
Uncaught SyntaxError: Unexpected token & Is there a way to get json in my js ?
Thanks
Edit:
In php
$dayArray = array('L','M','M','J','V','S','D'); $dayArray = json_encode($dayArray) In js
setDayArray('<?php echo $dayArray ?>'); setDayArray = function(dayArray){ console.log(dayArray); } With twig
calendar.setDayArray({{ dayArray }}); This is maybe due to symfony rendering, the only way I found is to do an ajax call using json header
htmlentities. No, don't just output it directly.setDayArray('<?php $dayArray ?>'). That's your problem right there, you have toechoit out.