Reputation: 23
just start to learn emberjs, appreciate your help!
There is a similar question raised for angular.js and answered (AngularJS : Insert HTML into view), however I can not find an answer using emberjs.
say I have {{A}} in template, and A = "html fragment" , defined in app.js. for example a html fragment as below:
<a href="www.google.com"> Go to Google! </a>
if i render the {{A}} in the view I will get exactly the string of that "html fragment" , however I wish there is a way that i could tell emberjs to render {{A}} as html.
Upvotes: 2
Views: 4151
Reputation: 3296
Handlebars is escaping your HTML fragment to protect you from possible malicious user input. The short answer to your question is to use Handlebars syntax to render the HTML in it's raw
form by using 3 curly braces: {{{A}}}
I would, however, recommend passing any string containing HTML through the htmlSafe
method to protect yourself. An example of usage can be found in the docs.
Upvotes: 11
Reputation: 341
I suggest use a flag as well in fallback scenario.
{{#if isHtmlSafe}}
{{A}}
{{else}}
{{{A}}}
{{/if}}
Here, "isHtmlSafe" is a property.
Upvotes: 0