Last active
January 13, 2018 21:38
-
-
Save mucahitnezir/7758c792f6a8cefe6bd815170f57e98f to your computer and use it in GitHub Desktop.
My custom handlebars template engine configuration
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
const express = require("express") | |
, exphbs = require("express-handlebars"); | |
/* Create express instance */ | |
var app = express(); | |
/* Configure hbs view engine */ | |
var hbs = exphbs({ | |
extname: 'hbs', | |
defaultLayout: 'mainLayout', | |
layoutsDir: __dirname + '/views/layouts/', | |
helpers: { | |
section: function(name, options) { | |
if (!this._sections) | |
this._sections = {}; | |
this._sections[name] = options.fn(this); | |
return null; | |
} | |
} | |
}); | |
/* Set view engine to express app */ | |
app.engine('hbs', hbs); | |
app.set('views', path.join(__dirname, 'views')); | |
app.set('view engine', 'hbs'); | |
/* Render a page */ | |
app.get('/', function() { | |
res.render('homepage'); | |
}); | |
/* Listen app */ | |
var port = 3000; | |
app.listen(port, function() { | |
console.log('Your app is ready at ' + port + ' port'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment