Reputation: 113
Is it possible to put handlebar template tag inside generated html string?
For example:
Ember.Handlebars.helper(...) {
return new Handlebars.SafeString("<button {{action go}}></button>");
}
I know this doesn't work but can anyone suggest the right way? (if exists)
Html source of that is:
<button {{action go}}></button>
but it should be something like that:
<button data-ember-action="x"></button>
where x is some integer
Cheers.
Upvotes: 1
Views: 485
Reputation: 19128
You can compile and call the template in runtime:
Ember.Handlebars.helper('trigger-action', function(options) {
var compiledTemplate = Ember.Handlebars.compile('</h1><a href="#" {{action go}}>Click</a>');
return compiledTemplate(null, options);
});
Sample http://emberjs.jsbin.com/uhedazok/1/edit
Keep in mind that the template is always compiled, so you can have some performance problems.
Upvotes: 1