Node.js - Express - Handlebars - Ex 1 // app2.js var express = require('express'); var exphbs = require('express-handlebars'); var simple = require('./simple'); var app = express(); app.engine('handlebars', exphbs({defaultLayout: 'main'})); app.set('view engine', 'handlebars'); // this middleware will be executed for every request to the app app.use(function (req, res, next) { console.log('Time: %d', Date.now()); next(); }) app.get('/', simple.home); app.get('/simple', simple.gorilla); app.listen(3000); /////////////////////////////////// // simple.js var simpleControllers = { 'home': function (req, res) { res.render('home'); }, 'gorilla': function (req, res) { var data = {name: 'Gorilla'}; res.render('simple', data); } }; module.exports = simpleControllers; /////////////////////////////////// // views/home.handlebars <h1>Example App: Home</h1> // views/simple.handlebars // (remove the express space between the curly braces. my template include code that exists within this blog app wants to execute what's inside the double curly braces) <h1>{ {name} }</h1> // views/layouts/main.handlebars <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Example App</title> </head> <body> { { {body} } } </body> </html> #nodejs - #javascript - #programming From JR's : articles 145 words - 1299 chars created on Nov 05, 2014 at 01:38:42 pm updated on Nov 05, 2014 at 01:44:02 pm - # source - versions