我正在尝试使用Node.js构建一个完整的web应用程序。是否有一个模板引擎类似于(例如)Django模板引擎或类似的,至少允许你扩展基本模板?
当前回答
如果你喜欢haml,但想要更好的东西,请检查http://jade-lang.com的节点,我也写了haml.js:)
其他回答
查看Node js模块wiki页面。他们列出了所有支持node.js的模板引擎。
老实说,Node.js最好、最简单的模板引擎是(IMHO) Plates (https://github.com/flatiron/plates)。你可能还想看看用于Node.js的Flatiron MVC框架(http://flatiron.org)。
尝试“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>
谷歌的闭包模板是一个原生javascript模板系统,看起来很适合NodeJS。下面是对它们进行积分的一些说明。