How can i make a json_encode inside a literal javascript block? Basically this is smarty template.
{literal}
<script>
function openWin() {
var O = {php} echo json_encode($obj);{/php}; // syntax error
alert(O);
}
</script>
{/literal}
It’s been a while since I had to fiddle with a Smarty template but I think you’d have to close the literal tag to run your php code. If you get an error, try removing the
echotoo – I can’t remember if it’s implicit or not when inside a smarty tag.Addendum:
Smarty syntax for echoing variables can also accommodate “filters” (ie. functions)