better layout control example
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 509601e · Browse files · 8 files·+65 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+65 added−22 removed
- other:+65 added−22 removed
Provenance
- Commit
23dbe6a- Tree
022dea2- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
509601e
8 files changed+65 added−22 removed
deleted:examples/layout-control/views/layouts/alternate.ejs-6 removed
1-<html>2- <body>3- <h1>Alternate Layout</h1>4- <%- body %>5- </body>6-</html>added:examples/layout-control/views/layouts/alternate.html+26 added
1234567891011121314151617181920212223242526<html> <title>Alternate</title> <style> body { padding: 50px; font: 14px "helvetica neue", helvetica, sans-serif; color: #333; } #sidebar { float: left; width: 150px; } #content { float: left; } </style> <body> <h1>Alternate Layout</h1> <div id="sidebar"> <p>Moar sidebar!</p> </div> <div id="content"> <%- body %> </div> </body></html>No newline at end of filedeleted:examples/layout-control/views/layouts/default.ejs-6 removed
1-<html>2- <body>3- <h1>Default Layout</h1>4- <%- body %>5- </body>6-</html>added:examples/layout-control/views/layouts/default.html+16 added
12345678910111213141516<html> <head> <title>Default</title> <style> body { padding: 50px; font: 14px "helvetica neue", helvetica, sans-serif; color: #333; } </style> </head> <body> <h1>Default Layout</h1> <%- body %> </body></html>No newline at end of filedeleted:examples/layout-control/views/pages/alternate.ejs-2 removed
1-<% layout('layouts/alternate') %>2-<h1>Page</h1>deleted:examples/layout-control/views/pages/default.ejs-1 removed
1-<h1>Page</h1>added:examples/layout-control/views/page.html+6 added
123456<h1>Page</h1><% if (path == '/alternate') { %> <p>Click <a href="/">here</a> to view the default layout.</p><% } else { %> <p>Click <a href="/alternate">here</a> to view the alternate layout.</p><% } %>modified:examples/layout-control/app.js+17 added-7 removed
1234566789101112131415161718191516171820212223242526212728293031323334353637283839404142
/** * Module dependencies. */
var express = require('../../lib/express');var express = require('../../lib/express') , url = require('url');
var app = express.createServer();
app.set('views', __dirname + '/views');
// map .html to ejs moduleapp.register('html', require('ejs'));app.set('view engine', 'html');
// set default layout, usually "layout"app.locals.layout = 'layouts/default';
// Set our default template engine to "ejs"// which prevents the need for extensions// (although you can still mix and match)app.set('view engine', 'ejs');// expose the current path as a view localapp.use(function(req, res, next){ res.locals.path = url.parse(req.url).pathname; next();});
app.get('/', function(req, res){ res.render('pages/default'); res.render('page');});
app.get('/alternate', function(req, res){ res.render('page', { layout: 'layouts/alternate' });});
app.get('/defined-in-view', function(req, res){ // note that we do not explicitly // state the layout here, the view does, // although we could do it here as well. res.render('pages/alternate'); res.render('pages');});
app.listen(3000);console.log('Express app started on port 3000');