app.js
This file
Path
examples/layout-control/app.js
52 lines · 1.1 KiB · JavaScript
Last changed by
another sidebarTj Holowaychukbefore adoptionc729d62
History of this fileTake it
The walk stopped after 200 commits: lines older than cd88b92 point at it.
Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92
lines 1–5why, one step back12/**3 * Module dependencies.4 */5better layout control exampleTj Holowaychukbefore adoption23dbe6a
lines 6–7why, one step back6var express = require('../../lib/express')7 , url = require('url');Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92
lines 8–12why, one step back89var app = express.createServer();1011app.set('views', __dirname + '/views');12better layout control exampleTj Holowaychukbefore adoption23dbe6a
lines 13–16why, one step back13// map .html to ejs module14app.register('html', require('ejs'));15app.set('view engine', 'html');16Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92
line 17why, one step back17// set default layout, usually "layout"fixed app.locals precedenceTj Holowaychukbefore adoption509601e
line 18why, one step back18app.locals.layout = 'layouts/default';Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92
line 19why, one step back19better layout control exampleTj Holowaychukbefore adoption23dbe6a
line 20why, one step back20app.use(function(req, res, next){sidebar exampleTj Holowaychukbefore adoption1793b50
line 21why, one step back21 // expose the current path as a view localbetter layout control exampleTj Holowaychukbefore adoption23dbe6a
line 22why, one step back22 res.locals.path = url.parse(req.url).pathname;sidebar exampleTj Holowaychukbefore adoption1793b50
line 23why, one step back23another sidebarTj Holowaychukbefore adoptionc729d62
line 24why, one step back24 // assign content str for sectionsidebar exampleTj Holowaychukbefore adoption1793b50
lines 25–28why, one step back25 res.locals.contentFor = function(section, str){26 res.locals[section] = str;27 };28 better layout control exampleTj Holowaychukbefore adoption23dbe6a
lines 29–30why, one step back29 next();30});Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92
lines 31–32why, one step back3132app.get('/', function(req, res){better layout control exampleTj Holowaychukbefore adoption23dbe6a
line 33why, one step back33 res.render('page');Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92
lines 34–36why, one step back34});3536app.get('/alternate', function(req, res){better layout control exampleTj Holowaychukbefore adoption23dbe6a
line 37why, one step back37 res.render('page', { layout: 'layouts/alternate' });another sidebarTj Holowaychukbefore adoptionc729d62
lines 38–41why, one step back38});3940app.get('/alternate2', function(req, res){41 res.render('page2');better layout control exampleTj Holowaychukbefore adoption23dbe6a
lines 42–44why, one step back42});4344app.get('/defined-in-view', function(req, res){Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92
lines 45–47why, one step back45 // note that we do not explicitly46 // state the layout here, the view does,47 // although we could do it here as well.better layout control exampleTj Holowaychukbefore adoption23dbe6a
line 48why, one step back48 res.render('pages');Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92
lines 49–52why, one step back49});5051app.listen(3000);52console.log('Express app started on port 3000');