Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs中使用ejs作为模板引擎如何使用layout #2

Open
milixie opened this issue Nov 2, 2016 · 0 comments
Open

nodejs中使用ejs作为模板引擎如何使用layout #2

milixie opened this issue Nov 2, 2016 · 0 comments

Comments

@milixie
Copy link
Owner

milixie commented Nov 2, 2016

1.在命令行中执行$ npm install express-partials
2.安装好后在app.js中
var partials = require('express-partials');
app.set('view engine', 'ejs');
app.use(partials());
3.layout.ejs中

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>ddd</title>
	</head>
	<body>
		<p>dddafaiefaoiedddddd</p>
		<%- body -%>
	</body>
</html>

4.不同页面指定不同的layout,则在该页面对应的js文件中:

var express = require('express');
var router = express.Router();

router.get('/', function(req, res, next) {
	res.render('about', { 
		time: '2014-01-12',
		ceo: 'mili',
		layout: 'layout2.ejs'  //指定对应的layout
	});
});

module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant