Reputation: 1228
I am trying to register a Handlebars.js helper in my Ember.js app that will allow me to pass in a view property that is a simple html string to be rendered without being escaped. My template looks like this:
<span class="add-on">{{log view.append}}{{safeMarkup view.append}}</span>
In this case the log statement outputs the html string properly to the console, something like <span>text</span>
.
My helper, safeMarkup, is as follows:
Handlebars.registerHelper('safeMarkup', (string) ->
return new Handlebars.SafeString(string)
)
Yet, what gets rendered is not the value of the view.append
property but the string "view.append" itself! Like so: <span class="add-on">view.append</span>
. Any ideas what's going wrong here?
Thanks
Upvotes: 3
Views: 1500
Reputation: 3872
You can also use triple-mustache to avoid escaping of the html string... http://jsbin.com/imafuq/8/edit
Upvotes: 0
Reputation: 4129
In handlebar:
{{span 'className'}}
In app:
Handlebars.registerHelper('span', function(className) {
return new Handlebars.SafeString("<span class='"+Handlebars.Utils.escapeExpression(className)+"'></span>");
});
Upvotes: 2