Created
September 4, 2016 16:31
-
-
Save jaksah/70fc400ce70664eaa47fcb47c34b307c to your computer and use it in GitHub Desktop.
Handlebars - Register all partials in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var hbs = require('hbs'); | |
// Register Partials | |
var partialsDir = __dirname + '/views/partials'; | |
var filenames = fs.readdirSync(partialsDir); | |
filenames.forEach(function (filename) { | |
var matches = /^([^.]+).hbs$/.exec(filename); | |
if (!matches) { | |
return; | |
} | |
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
You can also use