標籤:upload esc ext pat sea make link port 頁面
1、安裝
在網站根目錄啟動控制台,輸入
npm install ejs
Paste_Image.png
程式包會安裝到node_modules目錄下。
Paste_Image.png
2 修改APP.JS
修改app.js 將view engine修改為ejs。(並將模板的尾碼修改為.html)
app.set(‘views‘,path.join(__dirname , ‘views‘) ); app.engine(‘.html‘, require(‘ejs‘).__express); app.set(‘view engine‘, ‘html‘);
3 建立測試頁面
在views檔案夾中建立index.html,內容如下:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Pivotal Search</title> <meta name="description" content=""> <meta name="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>
然後在router裡修改index.js:
Paste_Image.png
/* GET home page. */router.get(‘/‘, function(req, res, next) { res.render(‘index‘, { title: ‘測試11111‘ });});
原文:http://www.cnblogs.com/xuanhun/p/3922847.html
在express網站中使用ejs模板引擎