Node.js開發 ---- Jade 模板引擎使用

來源:互聯網
上載者:User

標籤:set   nod   ansi   dir   查看   server   script   ade   console   

1.安裝jade外掛程式
npm install jade

2.app.js
[javascript] view plain copy 在CODE上查看代碼片派生到My Code片
var express = require(‘express‘);
var http = require(‘http‘);
var app = express();
app.set(‘view engine‘, ‘jade‘); // 設定模板引擎
app.set(‘views‘, __dirname); // 設定模板相對路徑(相對目前的目錄)

app.get(‘/‘, function(req, res) {
res.render(‘test‘); // 調用當前路徑下的 test.jade 模板
})

var server = http.createServer(app);
server.listen(3002);
console.log(‘server started on http://127.0.0.1:3002/‘);

3.test.jade
[html] view plain copy 在CODE上查看代碼片派生到My Code片
doctype html
html
title hello,jade
body
h1 Hello World

產生的html檔案
[html] view plain copy 在CODE上查看代碼片派生到My Code片
<!DOCtype html>
<html>
<head>
<title>hello,jade</title>
</head>

<body>
<h1>Hello World</h1>
</body>
</html>

html轉jade
http://html2jade.vida.io/

更多:
http://www.lellansin.com/jade-%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E%E4%BD%BF%E7%94%A8.html

Node.js開發 ---- Jade 模板引擎使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.