Created
October 3, 2012 00:29
-
-
Save benw/3824204 to your computer and use it in GitHub Desktop.
Loads partial handlebars templates from files in a directory
This file contains hidden or 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
// Helps with this problem: | |
// http://stackoverflow.com/questions/8059914/express-js-hbs-module-register-partials-from-hbs-file | |
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) { | |
return; | |
} | |
var name = matches[1]; | |
var template = fs.readFileSync(partialsDir + '/' + filename, 'utf8'); | |
hbs.registerPartial(name, template); | |
}); |
Author
benw
commented
Oct 11, 2022
via email
Handlebars, an html templating framework.
…On Wed, 20 Apr 2022 at 7:51 am, Michael Heilemann ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
What does require(hbs) load?
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/3824204#gistcomment-4138393>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADAYTDDRNRDWFHKBTFDLLVF4TFZANCNFSM4LA6HKJA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment