I am trying to get the content of a custom channel field (chan_body) inside a javascript variable (foo). I have set already in my config.php file
$config['protect_javascript'] = "n"; I have my chan_body 'Type' => 'TextArea' with 'Default Text Formatting => 'None' the problem is that this channel field is actually a couple lines long which is actually code in another language (that is not meant to be executed), but it's not getting escaped and just screwing up the javascript by getting dumped in there. How can I fix this? I tried escape() that did not help
{exp:channel:entries channel="mychannel" category="2"}
<script type="text/javascript">
var foo = "{chan_body}";
alert(foo);
</script>
{/exp:channel:entries}
translates to
<script type="text/javascript">
var foo = "my $testing = "myfile.txt";
Uncaught SyntaxError: Unexpected identifier
open(FILE,"$myfile ") or die;
# this is a comment
alert(foo);
</script>