0.1.2 • Published 9 years ago
easy-handlebars v0.1.2
easy-handlebars
Compilation of Handlebars templates from Gulp made easy.
Install the 'easy-handlebars' module:
npm install easy-handlebars --save-dev
Example.
- Compile your TPLs with Gulp:
var source = require('vinyl-source-stream');
gulp.task('tpl', function() {
var opts = {
// Optimize the following TPLs (use 'data = false' for this TPLs).
noData: ['login', 'signup', 'forgot-password'],
// Pass here the Handlebars's compiler options.
defaultCompilerOpts: { knownHelpersOnly: true, knownHelpers: ['basePath', 'breakLines'] }
};
return easyHandlebars('./src/views/partials/*.html', opts)
.pipe(source('tpl-bundle.js'))
.pipe(gulp.dest('./public/js'));
});
Include the 'Handlebars.runtime.js' library and the resulting .js file of compiling the TPLs in your app.
Use your TPLs:
var someTplFileNameTpl = Handlebars.partials['someTplFileName'];
var someTplFileNameHtml = someTplFileNameTpl();
document.getElementById('content').innerHTML = someTplFileNameHtml;