Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing HTML markup into handlebars

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

like image 300
Zach Shallbetter Avatar asked Mar 19 '13 17:03

Zach Shallbetter


1 Answers

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}}
like image 70
artahian Avatar answered Sep 22 '22 02:09

artahian