Show property which includes html tags

做~自己de王妃 提交于 2019-11-30 05:36:35

From http://handlebarsjs.com/

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

{{{expression}}}

Within Ember.js you can do this via the htmlSafe method, which is added to the String prototype, see http://jsfiddle.net/pangratz666/jNAQ6/:

Handlebars:

<script type="text/x-handlebars" >
    {{App.html}} - {{App.unescaped}}
</script>​

JavaScript:

App = Ember.Application.create({
    html: '<b>bold text</b>',
    unescaped: function(){
        return this.get('html').htmlSafe();
    }.property('html')
});​

Ember 2.x, using JavaScript

To make a string unescaped and output using Ember templates you can use htmlSafe helper.

Ember.String.htmlSafe('<div>someString</div>')

The returned string will not be HTML escaped by Handlebars template engine.

http://emberjs.com/api/classes/Ember.String.html#method_htmlSafe

Use Handlebars Only

Alternatively, you can pass the raw HTML to Handlebars template and get the raw HTML output by using triple brackets

Inside Handlebars Template

<div>{{{raw_html_content}}}</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!