This script help to load Handlebar templates and partials easily.
var loader = new HandlebarLoader();
loader.load(
[
'template1',
'template2',
'template3'
],
[
'partial1'
],
function()
{
// templates are available...
}
);
loader.getTemplate( 'template1' )();
var templateContainer = loader.getAllTemplates();
templateContainer.template1();
templateContainer.template2( { foo: 'bar' } );
By default, the loader will load template1
in tpl/template1.html
and partial1
in tpl/partials/partial1.html
.
Name | Definition | Default value |
---|---|---|
baseUrl | Define templates folder | tpl/ |
partialUrl | Define partials folder | tpl/partials/ |
extension | Define template & partial extension | html |
Define options at initialisation:
var loader = new HandlebarLoader( {
baseUrl: 'templates/',
partialUrl: 'partials/',
extension: 'hb'
} );
Now, this loader will load template1
in templates/template1.hb
and partial1
in partials/partial1.hb
.