Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars.js pass html in expression

Handlebar template

<div>
    {{contentText}}
</div>

JS

var contentText = {contentText: "<table><tr><td>Some Data<\/td><\/tr><\/table>"}

Handle bars render displays the HTML as string rather than rendering the HTML.

Where am I going wrong ?

like image 583
Anand Sunderraman Avatar asked Jan 12 '23 08:01

Anand Sunderraman


1 Answers

From the fine manual:

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.

So if you want to put contentText straight into the template as-is then you want:

<div>
    {{{contentText}}}
</div>

in your template.

Demo: http://jsfiddle.net/ambiguous/f7LJ5/

like image 69
mu is too short Avatar answered Apr 30 '23 02:04

mu is too short