转载自https://segmentfault.com/a/1190000005767260
新建默认layout
layout.ejs
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<% include header.ejs %>
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<% include menu.ejs %>
<div id="page-wrapper">
<div class="container-fluid">
<%- defineContent('pageSection') %>
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- foot js-->
<% include footer.ejs %>
</body>
</html>
配置
var expressLayouts = require('express-ejs-layouts');
app.use(expressLayouts);
新建部分页
<%- contentFor('pageSection') %>
this is home
render的时候render home
router.get('/home', function(req, res, next) {
res.render('home', { title: 'var',layout:"layout.ejs"});
});