在express網站中使用ejs模板引擎

來源:互聯網
上載者:User

標籤: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模板引擎

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.