Passing HTML markup into handlebars

html, javascript, jquery, json

Solution

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}}

Problem

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

Original source

Related problems