您好我想知道如何渲染dot.js模板引擎中的输出。我认为这是一个关于nodejs模板的通用问题(阅读评论以获取更多信息)。我之所以选择这个模板引擎而不是玉器或ejs,是因为它似乎是最快的引擎。如何在nodejs中渲染doT.js模板?
这里是我的app.js:
var express = require('express'),
app = express.createServer(),
doT = require('doT'),
pub = __dirname + '/public',
view = __dirname + '/views';
app.configure(function(){
app.set('views', view);
app.set('view options', {layout: false});
app.set('view engine', 'dot');
app.use(app.router);
});
app.register('.html', {
compile: function(str, opts){
return function(locals){
return str;
}
}
});
app.get('/', function(req, res){
//This is where I am trying to send data to the front end....
res.render('index.html', { output: 'someStuff' });
});
这里是我的html:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Index</title>
</head>
<body>
//This is where I am trying to receive data and output it...
{{=it.output}}
</body>
</html>
我只是找不到好它的文档。这还不够:http://olado.github.com/doT/。如果可以的话请帮忙。这将提高我对数据如何传递到nodejs视图的指数级理解。谢谢。
谢谢,这似乎工作。它总是退出来获取创建者的答案。我仍然需要弄清楚如何迭代我从mongodb中获得的记录,但这将是另一个问题......谢谢。 – user000001 2012-02-12 07:57:11
嗨,也许你可以看看[这个](http://stackoverflow.com/questions/9252191/show-all-of-data-comming-from-mongodb-and-render-it-in-dot-js-模板引擎)的问题,它基于你在这里回答的问题。我认为你是最有资格解决这个问题的人。如果可以的话请帮忙。 – user000001 2012-02-12 20:06:16
你可以请看看这个问题http://stackoverflow.com/questions/9252191/show-all-of-data-comming-from-mongodb-and-render-it-in-dot-js-templating-engine – user000001 2012-05-21 14:54:30