Original address: http://www.cnblogs.com/greenteaone/p/3685733.html
1. How to install the Ejs template engine in a project
Use the following command to establish the basic structure of your Web site in the Nodejs guide:
Express-t Ejs Microblog
Continue running after running this command
CD microblog && npm Install (dependency properties of the installation project),
found that the installed template engine is jade, not ejs. The reason is that the current version has no-t this command, instead
EXPRESS-E microblog
After running this command, continue running CD microblog && NPM install,ejs template engine is installed
But express3 above version of the layout by default to cancel, so now in the Views folder does not generate Layout.ejs.
2. When Ejs is installed, how to use the Ejs layout template
Installing Express-partials
Switch to the project directory in cmd, run npm install express-partials
or
package.json
added in the dependencies
inside "express-partials": "*"
. Then run under the project directory npm install
.
然后在app.js
Inside quoteexpress-partials,引用方法:
1. Adding referencesvar partials = require(‘express-partials‘);
2. app.set(‘view engine‘, ‘ejs‘);
Add the followingapp.use(partials());
Invoke the sample where you need to reference the template layout:‘模版名称‘
app.get(‘/reg‘, function (req, res) { res.render(‘reg‘, { title: ‘用户注册‘, layout: ‘template‘ }); });
How to refer to the Ejs template engine in the Express framework