I want to get handlebarjs template name using handlebar helper, how to do it? thanks! for example, give: a.hbs
<p>hello</p>
{{fileName}}
I want: a.html
hello a
I think that the easy and the safe way, is to get the template of the current view. And get your name, based in the identity, using Ember.TEMPLATES
.
Since the TEMPLATES
structure is { templateName: compiledTemplate }
.
Ember.Handlebars.registerHelper('filename', function(options) {
var template = options.data.view.get('template');
for (var templateName in Ember.TEMPLATES) {
if (Ember.TEMPLATES[templateName] === template) {
return templateName;
}
}
});
Live demo http://jsbin.com/ucanam/674/edit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.