Search code examples
jqueryjquery-templates

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


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');

Solution

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