Broccoli plugin that gives us an easy way to precompile Handlebars templates.
It opens every handlebar file and creates js file that can be later combine by different tool.
npm install --save broccoli-handlebars-precompiler
var broccoliHandlebars = require('broccoli-handlebars-precompiler');
var tree = broccoliHandlebars(tree, {
srcDir: 'js/templates',
namespace: 'App.templates'
});
Sample templates files.
productList.hbs
products/item.hbs
After precompiling with namespace 'App.templates' accessing those is quite easy.
Templates from main folder:
App.templates.productList({hondaCivic:"Honda Civic for sale", citroenXsara:"Citroen Xsara for sale"});
Templates from subfolders:
App.templates["products/item"]({name:"Honda Civic", price:"10.000"});
var tree = broccoliHandlebars(tree, options);
- tree - a broccoli tree
- options - options, see below
Source directory where handlebars are stored.
Namespace where all templates will be added. Default is Handlebars.templates.
Array of handlebars file extensions. Default is hbs and handlebars.
Array of target extensions. Default is js.