Reputation: 425
My code below in my HTML underscore template is literally printing out
"<sup>®</sup>"
on the page instead of the trademark replacement (®) I want the below code to do. What's wrong with my code? EDIT: I want designation.title and designation.description to print to the page, just replace the (R) in there with ®.
<%- designation.title.replace(/(®)/ig, "<sup>®</sup>") %>
<%- designation.description.replace(/(®)/ig, "<sup>®</sup>")%>
Upvotes: 1
Views: 110
Reputation: 18565
Create a DOM element and put your string in it. In your case, hand the el object to the method, not the string?
var output = document.getElementsByTagName('div')[0];
var output2 = document.getElementsByTagName('div')[1];
var el = document.createElement( 'div' );
el.innerHTML = "<sup>®</sup>";
var content = document.createTextNode("<sup>®</sup>");
output.appendChild(el);
// this does not work
output2.appendChild(content);
<div></div>
<div></div>
Upvotes: 0
Reputation: 141829
You're using the type of template function that does automatic escaping for HTML: <%-
instead of <%
. Using that will cause underscore to escape everything so that it can be output as is (output without being interpreted as HTML, so <
becomes <
, &
becomes &
, etc.
If you want to output raw HTML just drop the -
off <%-
, but that can be unsafe, depending on the rest of designation.title
and if it has any characters that need escaping.
Upvotes: 2