如何在nodejs中渲染doT.js模板? [英] How to render doT.js templating in nodejs?

查看:162
本文介绍了如何在nodejs中渲染doT.js模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在dot.js模板引擎中渲染输出。我认为这是一个关于nodejs模板的通用问题(阅读更多信息的评论)。我选择这个模板引擎而不是玉或ejs的原因是因为它似乎是最快的引擎。



这是我的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(localals){
return str;
}
}
});


app.get('/',function(req,res){

//这是我正在向前端发送数据的地方....
res.render('index.html',{output:'someStuff'});

});

这是我的html:

 <!DOCTYPE html> 
< html>
< head>
< meta charset ='utf-8'>
< title>索引< / title>
< / head>
< body>

//这是我正在尝试接收数据并输出...
{{it itoutout}}

< / body>
< / html>

我找不到很好的文档。这还不够: http://olado.github.com/doT/ 。如果可以的话请帮忙。这将提高我的理解指数数据如何传递到nodejs中的视图。谢谢。

解决方案

你需要让我们知道使用doT作为模板引擎:

  app.set(view engine,html); 
app.register('。html',doT);


Hi I would like to know how can I render output in dot.js templating engine. I think it's a generic question about nodejs templating.(read comments for more info). The reason why I chose this template engine instead of jade or ejs is because it seems the fastest engine around.

Here is my 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' });

});

Here is my 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>

I just could not find good docs on it. This was not enough: http://olado.github.com/doT/. Please help, if you can. This will improve my understanding exponentially of how data is passed to the view in nodejs. Thank you.

解决方案

You need to let express know to use doT as the template engine like this:

app.set("view engine", "html");
app.register('.html', doT);

这篇关于如何在nodejs中渲染doT.js模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆