有没有Node.js的模板引擎?

我正在尝试使用Node.js构build整个Web应用程序。 是否有一个类似(例如)Django模板引擎或类似的模板引擎,至less可以让你扩展基本模板?

查看Node js模块wiki页面。 他们列出了所有支持node.js的模板引擎 。

你应该可以使用mustache.js,如果不行的话把问题发给我,我会把它修好,因为我正要在node.js中使用它们。

http://github.com/janl/mustache.js

我知道它没有DOM,因为一堆CouchDB独立应用程序正在Spidermonkey视图服务器中使用它。

如果你喜欢haml,但是想要更好的东西,请查看http://jade-lang.com for node,我也写了haml.js 🙂

一直都有新的模板引擎。

underscore.js为js增加了很多function性的编程支持,并且有模板。

就在今天,我听说了这个: http : //github.com/SamuraiJack/Shotenjin-Joosed

您应该看看node-asyncEJS ,它明确地devise为考虑到node.js的asynchronous特性。 它甚至允许模板内的asynchronous代码块。

这里是一个文档的例子:

<html> <head> <% ctx.hello = "World"; %> <title><%= "Hello " + ctx.hello %></title> </head> <body> <h1><%? setTimeout(function () { res.print("Async Header"); res.finish(); }, 2000) %></h1> <p><%? setTimeout(function () { res.print("Body"); res.finish(); }, 1000) %></p> </body> </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> 

我已经在Simon Willisons djangode项目的Django模板语言( Node.js的实用程序函数,从Django中借用了一些有用的概念)的相当完整的端口上做了一些工作。

请参阅这里的文档。

我在Symfony中使用Twig,现在在node.js中进行游戏,所以我正在寻找https://github.com/justjohn/twig.js和https://github.com/paularmstrong/swig ,可能就像你使用Django。

如果您正在寻找模板的简约方法,您可以查看JSON模板 。

一个更全面的select是EJS 。 这和Django的一些东西有些相似。

你的里程可能会有所不同 – 它们是为浏览器的Javascript环境devise的,而不是Node.js.

警告:JinJs不再被维护。 它仍然工作,但与最新版本的快递不兼容。

你可以尝试使用jinjs 。 这是一个非常好的Python模板系统Jinja的一个端口。 你可以像这样用npm来安装它:

 npm install jinjs 

在template.tpl中:

 I say : "{{ sentence }}" 

在你的template.js中:

 jinjs = require('jinjs'); jinjs.registerExtension('.tpl'); tpl = require('./template'); str = tpl.render ({sentence : 'Hello, World!'}); console.log(str); 

输出将是:

 I say : "Hello, World!" 

我们正在积极开发它,一个好的文档应该很快就会来。

尝试“vash” – asp.net mvc像node.js的razor语法

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); 

Google的Closure模板是一个本地化的JavaScript模板系统,与NodeJS看起来很合适。 以下是一些整合的说明 。

haml是node.js的不错select

http://github.com/creationix/haml-js

HAML-JS

 !!! XML !!! strict %html{ xmlns: "http://www.w3.org/1999/xhtml" } %head %title Sample haml template %body .profile .left.column #date= print_date() #address= current_user.address .right.column #email= current_user.email #bio= current_user.bio 

HTML

 <?xml version='1.0' encoding='utf-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Sample haml template </title></head><body><div class="profile"><div class="left column"><div id="date">January 1, 2009 </div><div id="address">Richardson, TX </div></div><div class="right column"><div id="email">tim@creationix.com </div><div id="bio">Experienced software professional... </div></div></div></body></html> 

你尝试过PURE吗?
如果您尝试一下,请随时发布您在论坛上可能遇到的任何问题

虽然它主要是为浏览器devise的,但它与Jaxer和Rhino的效果很好。

我不知道node.js,但是如果你可以在内存中caching一些JS和函数,速度应该会更加令人印象深刻。

有一个JavaScript的Django模板引擎的端口。 但是,它并没有被更新很长一段时间,但它可能仍然有足够的function。

http://code.google.com/p/jtl-javascript-template/

试试Yajet吧 。 ;-)这是我昨天刚刚发布的一个新的,但我现在使用它,它稳定和快速(模板被编译为本地JSfunction)。

它具有IMO模板引擎可能的最佳语法,尽pipe其代码尺寸较小(8.5K缩小),但仍具有丰富的function集。 它有指令,允许你引入条件,迭代数组/散列,定义可重用的模板组件等。

我从Twitter上find了hogan.js ,并在他的网站上被Tim O'Reilly推荐。 我没有最好的做法,但我相信Twitter和O'Reilly。 你应该试试…

老实说,最好的和最简单的Node.js模板引擎是(恕我直言)板( https://github.com/flatiron/plates )。 你可能也想看看Node.js( http://flatiron.org )的Flatiron MVC框架。

您可以使用DojoToolkit.org的dojox.dtl。 请注意,dojo 1.7可以很好地在NodeJS上运行,并作为服务器端库执行。 如果你有兴趣,我可以给你一个简单的例子。