Is there a helper function that will properly escape a string to be rendered as a single quote quoted JavaScript string literal?
I know of jsQuoteEscape but it only handles quotes and does not treat \n & \r etc.
so if my string is ‘line1\nlineb’ (i.e. two lines with a newline between them)
and I use
var jsvar='<?php echo $this->helper('myextension')->jsQuoteEscape($mystring); ?>';
I will get in the rendered content
var jsvar='line1
line2';
which is a syntax error.
Thanks,
Eyal
Yes
I’ve never been clear if this encoding a non-object string datatypes as a javascript string is a side-effect of the JSON encoding, or if it’s true, according to
HoyleCrockford JSON, so I always like to wrap my strings in an object when passing them aroundThis is how you’d handle this with javascript. There’s no method that’s build specifically for this. If you’re interested in seeing the helper methods you do have available from a block, checkout the methods in
and if you’re dealing with a template that’s part of a block higher up the chain, get its class and then check its definition