Search code examples
javascriptbackbone.jsunderscore.js

textarea in backbone and underscore html decoding the content


I am using backbone.js with underscore.js

In my template I have the following textarea

<textarea id="MyHtml" rows="10" cols="75" name="MyHtml"><%= MyHtml %></textarea>

Now the issue is if my model's MyHtml has any ascii character it html decodes it and renders it. To know exactly what i mean check this fiddle.

How do I use the above template and still prevent this ?


Solution

  • Inside your UnderScore Templates use minus sign ("-") for binding value to your html field instead of equals ("=") For eg.

    <textarea id="MyHtml" rows="10" cols="75" name="MyHtml"><%- MyHtml %></textarea>