1. Installation
Start the console at the root of the Web site, enter
install ejs
Paste_image.png
The package is installed in the Node_modules directory.
Paste_image.png
2 modifying App.js
Modify App.js to change the view engine to Ejs. (and modify the suffix of the template to. html)
app.set(‘views‘,path.join(__dirname , ‘views‘) ); app.engine(‘.html‘, require(‘ejs‘).__express); app.set(‘view engine‘, ‘html‘);
3 Creating a test page
Create the index.html in the Views folder, as follows:
<! DOCTYPE html><Htmllang="EN" ><Head><Metacharset="UTF-8" ><Title>pivotal Search</Title><MetaName="description"Content="" ><MetaName="Author"Content="" ><!--HTML5 Shim, for ie6-8 support of HTML elements--<!--[if Lt IE 9]> <script src= "Http://apps.bdimg.com/libs/html5shiv/r29/html5.min.js" ></script > <! [endif]--> <!--styles-- <link href="css/style.css" rel="stylesheet" > </head><body> <%= title %></ body> </html>
Then modify the index.js in the router:
Paste_image.png
/* GET home page. */router.get(‘/‘, function(req, res, next) { res.render(‘index‘, { title: ‘测试11111‘ });});
Original: http://www.cnblogs.com/xuanhun/p/3922847.html
Using the Ejs template engine in the Express site