Skip to content

Instantly share code, notes, and snippets.

@kenichi
Created February 22, 2018 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenichi/eb2392ada97211906d6a5c5b9ef5b011 to your computer and use it in GitHub Desktop.
Save kenichi/eb2392ada97211906d6a5c5b9ef5b011 to your computer and use it in GitHub Desktop.
express serve partials from outside tree
#!/usr/bin/env node
const app = require('express')();
const viewsDir = __dirname + '/views';
const otherDir = __dirname + '/../ax';
const hbs = require('express-handlebars').create({
defaultLayout: 'main',
layoutsDir: viewsDir + '/layouts',
partialsDir: [
viewsDir + '/partials',
otherDir
],
extname: '.hbs'
});
app.engine('.hbs', hbs.engine);
app.set('view engine', '.hbs');
app.set('views', viewsDir);
app.get('/', function (req, res) {
res.render('index');
});
app.listen(3000, function () {
console.log('listening on: 3000');
});
@kenichi
Copy link
Author

kenichi commented Feb 22, 2018

../ax/header.hbs is outside the tree, views/index.hbs has:

{{> header}}

in it and it renders properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment