How to render HTML as rendered HTML in jQuery.tmpl()?

eugeneK picture eugeneK · Jun 6, 2011 · Viewed 9.8k times · Source

I can't assign HTML properly using jQuery.tmpl(). If i pass value of something as html tag it is rendered as as it is instead of HTML tags rendered on page

<div id="window">
    <script id="lines" type="text/x-jquery-tmpl">
        <div id="${id}" class="line ${type}"><span>${name}</span>: ${body}</div>
    </script>
</div>



var line = {
            name: 'John',
            body: '<strong>hello</strong>
        };
        $('#lines').tmpl(line).appendTo('#window');

Answer

Dvir Azulay picture Dvir Azulay · Jun 6, 2011

You can wrap the template variable with {{html body}} to override the default encoding behavior.