Show property which includes html tags

*爱你&永不变心* 提交于 2019-12-30 01:34:05

问题


I've an ember property which includes html tags (<br />, <strong>, <p>, <span>, and similar stuff).

How can i tell ember not to escape this text? Is there any default Handlebars helper from ember, or need I to write my own?


回答1:


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}}}




回答2:


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



回答3:


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>


来源:https://stackoverflow.com/questions/11450602/show-property-which-includes-html-tags

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