Example for outputting as typical Handlebars precompiling explanation
Closed this issue · 1 comments
Hey, I'm a little confused at the way these are compiled in comparison to how I was doing it before (how Handlebars.js actually tell you to do it).
http://handlebarsjs.com/precompilation.html
"The compiler will insert templates in Handlebars.templates. If your input file is person.handlebars, the compiler will insert it at Handlebars.templates.person."
Is it possible to replicate this at all by config?
Was hoping to do
'public/js/templates.js': 'public/js/templates/*.handlebars'
And then use them by their filename so:
game.handlebars = Handlebars.templates.game
thing.handlebars = Handlebars.templates.thing
For anyone still looking, I managed it:
handlebars: {
compile: {
files: {
"public/js/templates/templates.js": "public/js/templates/*.hbs"
},
options: {
namespace: 'Handlebars.templates',
processName: function(filePath) {
var pieces = filePath.split("/");
return pieces[pieces.length - 1].replace('.hbs', '');
}
}
}
}
This will take all .hbs files inside pubilc/js/templates directory and make these templates available like:
public/js/templates/game.hbs = Handlebars.templates.game
public/js/templates/game-details.hbs = Handlebars.templates['game-details']
Enjoy!