I have JSON String in PHP.
Index.php
$myObj = "{ "name":"John", "age":31, "city":"New York" }";
$smartyVars['MyObject'] = filter_var($myObj, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
I am using MyObject var in tpl file with Js.
index.tpl
<script>
var myObj = "{$MyObject}"
$("input#valDef").val(myObj);
</script>
I want to use escape in tpl file
var myObj = "{$MyObject|escape}"
After including escape how js give an error and my JS Distorted. my code not working properly. Without escaping its working fine.
But for the security concern, I want to add escape in smarty template and I already SANITIZE my JSON in PHP as you see above the PHP code.
So Please help how to add and work properly.