mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 00:19:48 +01:00
parent
64dd446aa8
commit
f44368f8be
|
|
@ -3,11 +3,12 @@
|
|||
*/
|
||||
|
||||
var express = require('../..');
|
||||
var path = require('path');
|
||||
var User = require('./user');
|
||||
var app = express();
|
||||
|
||||
app.set('views', __dirname);
|
||||
app.set('view engine', 'jade');
|
||||
app.set('views', path.join(__dirname, 'views'));
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
// filter ferrets only
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ app.get('/', function(req, res, next){
|
|||
if (err) return next(err);
|
||||
User.all(function(err, users){
|
||||
if (err) return next(err);
|
||||
res.render('user', {
|
||||
res.render('index', {
|
||||
title: 'Users',
|
||||
count: count,
|
||||
users: users.filter(ferrets)
|
||||
|
|
@ -59,7 +60,7 @@ function users(req, res, next) {
|
|||
}
|
||||
|
||||
app.get('/middleware', count, users, function(req, res, next){
|
||||
res.render('user', {
|
||||
res.render('index', {
|
||||
title: 'Users',
|
||||
count: req.count,
|
||||
users: req.users.filter(ferrets)
|
||||
|
|
@ -101,7 +102,7 @@ app.get('/middleware-locals', count2, users2, function(req, res, next){
|
|||
// to pass to res.render(). If we have
|
||||
// several routes related to users this
|
||||
// can be a great productivity booster
|
||||
res.render('user', { title: 'Users' });
|
||||
res.render('index', { title: 'Users' });
|
||||
});
|
||||
|
||||
// keep in mind that middleware may be placed anywhere
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
doctype html
|
||||
html
|
||||
head
|
||||
title= title
|
||||
style.
|
||||
body {
|
||||
padding: 50px;
|
||||
font: 16px Helvetica, Arial;
|
||||
}
|
||||
body
|
||||
h2= title
|
||||
block content
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
extends layout
|
||||
|
||||
block content
|
||||
for user in users
|
||||
.user
|
||||
h3= user.name
|
||||
p #{user.name} is a #{user.age} year old #{user.species}.
|
||||
19
examples/view-locals/views/index.ejs
Normal file
19
examples/view-locals/views/index.ejs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><%= title %></title>
|
||||
<style media="screen">
|
||||
body {
|
||||
padding: 50px;
|
||||
font: 16px Helvetica, Arial;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2><%= title %></h2>
|
||||
<% users.forEach(function(user) { %>
|
||||
<li><strong><%= user.name %></strong> is a <% user.age %> year old <%= user.species %></li>
|
||||
<% }); %>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user