Created
May 23, 2013 09:21
-
-
Save lucidstack/5633916 to your computer and use it in GitHub Desktop.
How to use helpers in Express 3.x
This file contains 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
//helpers.js | |
var moment = require('moment'); | |
var helpers = { | |
nice_date: function(raw_date) { | |
return moment(raw_date).format('LL'); | |
} | |
}; | |
module.exports.load = function(app) { | |
_.extend(app.locals, helpers); | |
}; | |
//app.js (MAIN) | |
var helpers = require('./helpers.js'); | |
var urls = require('./urls.js'); | |
var start_server = function() { | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'jade'); | |
app.use(express.static(__dirname + '/public')); | |
app.use(express.logger()); | |
helpers.load(app); // <---------- | |
urls.load(app); | |
app.listen(3000); | |
}; | |
//and the in any view | |
p(style='font-family: Droid;') Price: <strong> € #{comic.price} </strong> - <em> #{nice_date(comic.date)} </em> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment