我正在尝试使用Node.js构建一个完整的web应用程序。是否有一个模板引擎类似于(例如)Django模板引擎或类似的,至少允许你扩展基本模板?
当前回答
你应该能够使用mustache.js,如果它不工作,请把问题发给我,我会把它修复,因为我即将在node.js中使用它们。
http://github.com/janl/mustache.js
我知道它可以在没有DOM的情况下工作,因为很多CouchDB独立应用程序在Spidermonkey视图服务器中使用它。
其他回答
尝试“vash”- net mvc类似razor语法的node.js
https://github.com/kirbysayshi/Vash
也可以查看:http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
// sample
var tmpl = vash.compile('<hr/>@model.a,@model.b<hr/>');
var html = tmpl({"a": "hello", "b": "world"});
res.write(html);
你可以试试无胡子(它的灵感来自焊接/板):
例如:
{ post:
{ title: "Next generation templating: Start shaving!"
, text: "TL;DR You should really check out beardless!"
, comments:
[ {text: "Hey cool!"}
, {text: "Really gotta check that out..."} ]
}
}
你的模板:
<h1 data-template="post.title"></h1>
<p data-template="post.text"></p>
<div>
<div data-template="post.comments" class="comment">
<p data-template="post.comments.text"></p>
</div>
</div>
输出:
<h1>Next generation templating: Start shaving!</h1>
<p>TL;DR You should really check out beardless!</p>
<div>
<div class="comment">
<p>Hey cool!</p>
</div>
<div class="comment">
<p>Really gotta check that out...</p>
</div>
</div>
你应该能够使用mustache.js,如果它不工作,请把问题发给我,我会把它修复,因为我即将在node.js中使用它们。
http://github.com/janl/mustache.js
我知道它可以在没有DOM的情况下工作,因为很多CouchDB独立应用程序在Spidermonkey视图服务器中使用它。
我听说过关于{dust} http://akdubya.github.com/dustjs/#dust的好事情
你可以使用dojox。DojoToolkit.org的dtl。请注意,dojo 1.7可以很好地运行在NodeJS上,并作为服务器端库执行。如果你感兴趣,我可以给你一个简单的例子。