Skip to content
Myr

app.js

This file

Path

examples/layout-control/app.js

52 lines · 1.1 KiB · JavaScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than f98c112 point at it.

Added app.render() local precedence testTj Holowaychukbefore adoptionf98c112

lines 1–52why, one step back
1
2/**3 * Module dependencies.4 */56var express = require('../../lib/express')7 , url = require('url');89var app = express.createServer();1011app.set('views', __dirname + '/views');1213// map .html to ejs module14app.register('html', require('ejs'));15app.set('view engine', 'html');1617// set default layout, usually "layout"18app.locals.layout = 'layouts/default';1920app.use(function(req, res, next){21 // expose the current path as a view local22 res.locals.path = url.parse(req.url).pathname;2324 // assign content str for section25 res.locals.contentFor = function(section, str){26 res.locals[section] = str;27 };28 29 next();30});3132app.get('/', function(req, res){33 res.render('page');34});3536app.get('/alternate', function(req, res){37 res.render('page', { layout: 'layouts/alternate' });38});3940app.get('/alternate2', function(req, res){41 res.render('page2');42});4344app.get('/defined-in-view', function(req, res){45 // note that we do not explicitly46 // state the layout here, the view does,47 // although we could do it here as well.48 res.render('pages');49});5051app.listen(3000);52console.log('Express app started on port 3000');