Skip to content

Instantly share code, notes, and snippets.

@rgrove
Created February 24, 2012 20:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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