Skip to content
Myr

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 file

Take 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 back
1
2/**3 * Module dependencies.4 */5

better layout control exampleTj Holowaychukbefore adoption23dbe6a

lines 6–7why, one step back
6var express = require('../../lib/express')
7 , url = require('url');

Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92

lines 8–12why, one step back
8
9var app = express.createServer();1011app.set('views', __dirname + '/views');12

better layout control exampleTj Holowaychukbefore adoption23dbe6a

lines 13–16why, one step back
13// map .html to ejs module
14app.register('html', require('ejs'));15app.set('view engine', 'html');16

Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92

line 17why, one step back
17// set default layout, usually "layout"

fixed app.locals precedenceTj Holowaychukbefore adoption509601e

line 18why, one step back
18app.locals.layout = 'layouts/default';

Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92

line 19why, one step back
19

better layout control exampleTj Holowaychukbefore adoption23dbe6a

line 20why, one step back
20app.use(function(req, res, next){

sidebar exampleTj Holowaychukbefore adoption1793b50

line 21why, one step back
21 // expose the current path as a view local

better layout control exampleTj Holowaychukbefore adoption23dbe6a

line 22why, one step back
22 res.locals.path = url.parse(req.url).pathname;

sidebar exampleTj Holowaychukbefore adoption1793b50

line 23why, one step back
23

another sidebarTj Holowaychukbefore adoptionc729d62

line 24why, one step back
24 // assign content str for section

sidebar exampleTj Holowaychukbefore adoption1793b50

lines 25–28why, one step back
25 res.locals.contentFor = function(section, str){
26 res.locals[section] = str;27 };28

better layout control exampleTj Holowaychukbefore adoption23dbe6a

lines 29–30why, one step back
29 next();
30});

Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92

lines 31–32why, one step back
31
32app.get('/', function(req, res){

better layout control exampleTj Holowaychukbefore adoption23dbe6a

line 33why, one step back
33 res.render('page');

Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92

lines 34–36why, one step back
34});
3536app.get('/alternate', function(req, res){

better layout control exampleTj Holowaychukbefore adoption23dbe6a

line 37why, one step back
37 res.render('page', { layout: 'layouts/alternate' });

another sidebarTj Holowaychukbefore adoptionc729d62

lines 38–41why, one step back
38});
3940app.get('/alternate2', function(req, res){41 res.render('page2');

better layout control exampleTj Holowaychukbefore adoption23dbe6a

lines 42–44why, one step back
42});
4344app.get('/defined-in-view', function(req, res){

Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92

lines 45–47why, one step back
45 // note that we do not explicitly
46 // 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 back
48 res.render('pages');

Removed `app.dynamicLocals()`. Closes #756Tj Holowaychukbefore adoptioncd88b92

lines 49–52why, one step back
49});
5051app.listen(3000);52console.log('Express app started on port 3000');