I have an unusual situation where a client would like to place a line break in a string that is passed to handlebars from a JSON object. I've tried escaping characters but it isn't rendered by the DOM unsurprisingly. Any suggestions?
"company": "Lorem adscs ireland <br/> marketed as iuhmdsf in Europe"
var products = Data;
var theTemplateScript = $("#product-template").html();
var theTemplate = Handlebars.compile (theTemplateScript);
$("#marketed-products .products").append (theTemplate(products));
{{#items}}
<li><span class="company">{{company}}</li>
{{/items}}
The output from the code above should look something like this
Lorem adscs ireland
marketed as iuhmdsf in Europe
Use triple brackets, like {{{returnedHtml}}}
, in that case Handlebars will not escape the value.
i.e it will become:
{{#items}}
<li><span class="company">{{{company}}}</li>
{{/items}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With