nodejs 更換jade,使用doT模板引擎

參考:http://alistapart.com/article/node-at-work-a-walkthroughnode

express不直接支持dot模板引擎,npm提供了一個兼容插件consolidateexpress

 

 1 var express = require('express');
 2 var http = require('http');
 3 var path = require('path');
 4 var favicon = require('static-favicon');
 5 var logger = require('morgan');
 6 var cookieParser = require('cookie-parser');
 7 var bodyParser = require('body-parser');
 8 var dot = require('dot');
 9 //consolidate 爲express提供兼容其餘模版引擎的方法
10 var consolidate = require('consolidate');
11 
12 var routes = require('./routes');
13 var users = require('./routes/user');
14 
15 var app = express();
16 
17 // view engine setup
18 //var dots = dot.process({ path: "./views"});
19 //console.log(dots);
20 //dots.template({foo: "Hello World!"});
21 
22 app.set('views', path.join(__dirname, 'views'));
23 
24 app.engine('dot', consolidate.dot);
25 app.set('view engine', 'dot');
26 //app.set('views', path.join(__dirname, 'views'));
27 //app.set('view engine', 'jade');
28 console.log(app);

 

views下的模板後綴是.dotnpm

在routes/index.js裏render要輸出的數據:cookie

exports.index = function(req, res){
  res.render('index', { title: 'Express' });
};

 

index.dot輸出變量:app

<div>{{=it.title}}</div>

這個it是express的仍是doT的?驗證下ui

必定要使用express的iterator來輸出spa

相關文章
相關標籤/搜索