John Hunt
John Hunt

Reputation: 4072

Escaping quotes from expressionengine's output for Javascript

I have the following in one of my EE templates:

<!-- Set up dynamic js array for notebook data -->
<script type="text/javascript">
notebooks = [{exp:channel:entries channel="product-notebooks" dynamic="no" backspace="1"}
{"entry_id": "{entry_id}",
"notebook_covertext": "{notebook-covertext}",
"notebook_image": "{notebook-image}"}
,{/exp:channel:entries}
]
</script>

Basically I'd like {notebook-covertext} to escape or htmlentity-ize the content.. anyone know how I can achieve this?

Cheers, John.

Upvotes: 0

Views: 899

Answers (2)

CreateSean
CreateSean

Reputation: 1386

You could also try this hidden config variable

$config['protect_javascript'] = 'y';

Upvotes: 3

Derek Hogue
Derek Hogue

Reputation: 4564

This plugin should do the trick.

"notebook_covertext": "{exp:mah_eencode}{notebook-covertext}{/exp:mah_eencode}",

Upvotes: 1

Related Questions