Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Loads partial handlebars templates from files in a directory
// Helps with this problem:
var hbs = require('hbs');
var fs = require('fs');
var partialsDir = __dirname + '/../views/partials';
var filenames = fs.readdirSync(partialsDir);
filenames.forEach(function (filename) {
var matches = /^([^.]+).hbs$/.exec(filename);
if (!matches) {
var name = matches[1];
var template = fs.readFileSync(partialsDir + '/' + filename, 'utf8');
hbs.registerPartial(name, template);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment