我正在尝试使用Node.js构建一个完整的web应用程序。是否有一个模板引擎类似于(例如)Django模板引擎或类似的,至少允许你扩展基本模板?
当前回答
我在Symfony中使用Twig,现在正在尝试node.js,所以我正在寻找https://github.com/justjohn/twig.js和https://github.com/paularmstrong/swig,如果你使用django,你可能会喜欢。
其他回答
一直都有新的模板引擎。
js为js添加了大量的函数式编程支持,并且有模板。
就在今天,我听说了这个:http://github.com/SamuraiJack/Shotenjin-Joosed
也试试Yajet吧。;-)这是我昨天刚刚发布的一个新版本,但我现在已经使用了一段时间,它稳定而快速(模板被编译为原生JS函数)。
对于模板引擎来说,它具有IMO最好的语法,尽管代码大小较小(减小了8.5K),但功能集丰富。它的指令允许你引入条件,迭代数组/哈希,定义可重用的模板组件等。
你可以试试无胡子(它的灵感来自焊接/板):
例如:
{ 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>
老实说,Node.js最好、最简单的模板引擎是(IMHO) Plates (https://github.com/flatiron/plates)。你可能还想看看用于Node.js的Flatiron MVC框架(http://flatiron.org)。
我在Symfony中使用Twig,现在正在尝试node.js,所以我正在寻找https://github.com/justjohn/twig.js和https://github.com/paularmstrong/swig,如果你使用django,你可能会喜欢。