Upgrade to Pro — share decks privately, control downloads, hide ads and more …

15 Things I Learned About Handlebars

Ryan Lewis
September 17, 2015

15 Things I Learned About Handlebars

A list of things I learned while researching my next course for Pluralsight: JavaScript Templating with Handlebars.

Ryan Lewis

September 17, 2015
Tweet

More Decks by Ryan Lewis

Other Decks in Programming

Transcript

  1. Handlebars.partials[‘awesome-templ’] = ’{{#if isCorrect}} Awesome {{/if}}’; Handlebars.registerPartial(‘awesome-templ’, ‘{{#if isCorrect}} Awesome

    {{/if}}’); Handlebars.partials[‘awesome-templ’] = function() { //render }}; //some template is rendered with partial
  2. { name: ‘Ness’, city: ‘Onett’, isCorrect: true } Handlebars.registerHelper(‘isCorrect’, function()

    { return false; }); {{#if isCorrect}} I’m right! {{/if}} GORV[UVTKPI
  3. server.views({ engines: { html: require('handlebars') }, path: __dirname + '/templates',

    partialsPath: __dirname + '/templates/partials' }); hapi.js express.js No first class support for Handlebars ‘express-handlebars’ works okay
  4. Feb. 2011 0.9 May 2013 1.0 Sep. 2014 2.0 Feb.

    2015 3.0 Sep. 2015 4.0 Handlebars Release Timeline Version 5.0 coming Feb. 2016?
  5. handlebars: { compile: { options: { namespace: "JST" }, files:

    { "result.js": "source.hbs" } } } grunt-contrib-handlebars module.exports = function() { var partials = gulp.src(['./templates/_*.hbs']) .pipe(handlebars()) .pipe(wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, Handlebars.template(<%= contents %>));', {}, { imports: { processPartialName: function(fileName) { return JSON.stringify(path.basename(fileName, '.js').substr(1)); } } })); var templates = gulp.src('./templates/[^_]*.hbs') .pipe(handlebars()) .pipe(wrap('Handlebars.template(<%= contents %>)')) .pipe(declare({ namespace: 'App.templates', noRedeclare: true })); return merge(partials, templates) .pipe(concat('templates.js')) .pipe(gulp.dest('./build/js/')); }; gulp-handlebars