Skip to content

Instantly share code, notes, and snippets.

@rgrove
Created February 24, 2012 20:57
Show Gist options
  • Save rgrove/1903696 to your computer and use it in GitHub Desktop.
Save rgrove/1903696 to your computer and use it in GitHub Desktop.
Simple Handlebars view engine for Express
var express = require('express'),
app = express.createServer();
app.configure(function () {
// Use our custom Handlebars-based view engine as the default.
app.register('.handlebars', require('./view'));
app.set('view engine', 'handlebars');
// ...
});
// ...
var Handlebars = require('../support/handlebars/handlebars.js').Handlebars;
// Export a compile() method for Express.
exports.compile = function (source, options) {
var template = Handlebars.compile(source);
return function (options) {
return template(options, options.helpers);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment