Node.js 有模板引擎吗?
我正在尝试使用 Node.js 构建整个 Web 应用程序。是否有类似于(例如)Django 模板引擎之类的模板引擎,至少允许您扩展基本模板?
I'm experimenting with building an entire web application using Node.js. Is there a template engine similar to (for example) the Django template engine or the like that at least allows you to extend base templates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(21)
下面对几款引擎进行了很好的评价
http://engineering.linkedin.com /frontend/client-side-templated-throwdown-mustache-handlebars-dustjs-and-more
Here's a good evaluation of several engines
http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more
老实说,Node.js 最好、最简单的模板引擎是(恕我直言)Plates(https://github.com/熨斗/盘子)。您可能还想查看 Node.js 的 Flatiron MVC 框架 (http://flatiron.org)。
Honestly, the best and most simple template engine for Node.js is (IMHO) Plates (https://github.com/flatiron/plates). You might also want to check out the Flatiron MVC framework for Node.js (http://flatiron.org).
您可以使用DojoToolkit.org 的dojox.dtl。请注意,dojo 1.7 可以很好地在 NodeJS 上运行并作为服务器端库执行。如果您有兴趣,我可以给您举一个简单的例子。
You can use dojox.dtl of DojoToolkit.org. Note that dojo 1.7 can well run on NodeJS and perform as a server side library. If you're interested, I can give you a simple example.
查看 Node js 模块 wiki 页面。他们列出了所有支持 Node.js 的模板引擎。
Check out the Node js modules wiki page. They have listed all the templating engines supporting node.js.
您应该能够使用 Mustache.js,如果它不起作用,请将问题发送给我,我会修复它,因为无论如何我都将在 Node.js 中使用它们。
http://github.com/janl/mustache.js
我知道它无需 DOM 即可工作因为一堆 CouchDB 独立应用程序在 Spidermonkey 视图服务器中使用它。
You should be able to use mustache.js, if it doesn't work send me the issues and I'll get it fixed because I'm about to be using them in node.js anyway.
http://github.com/janl/mustache.js
I know that it works without a DOM because a bunch of CouchDB standalone apps are using it in a Spidermonkey view server.
如果你喜欢 haml,但想要更好的东西,请查看 http://jade-lang.com for Node,我也写了 haml.js :)
If you like haml, but want something even better check out http://jade-lang.com for node, I wrote haml.js as well :)
一直有新的模板引擎出现。
underscore.js为js添加了很多函数式编程支持,并且具有模板化功能。
就在今天,我听说了这个: http://github.com/SamuraiJack/Shotenjin-Joosed
There are new templating engines all the time.
underscore.js adds a lot of functional programming support to js, and has templating.
And just today I heard about this: http://github.com/SamuraiJack/Shotenjin-Joosed
您应该看一下node-asyncEJS,它被明确设计为采用节点的异步特性.js 考虑在内。它甚至允许模板内的异步代码块。
这是文档的示例:
You should take a look at node-asyncEJS, which is explicitly designed to take the asynchronous nature of node.js into account. It even allows async code blocks inside of the template.
Here an example form the documentation:
您可以尝试 beardless (它的灵感来自焊接/板):
例如:
您的模板:
输出:
You can try beardless (it's inspired by weld/plates):
For example:
Your template:
Output:
我已经为 Simon Willisons djangode 项目 做了一些相当完整的 Django 模板语言移植工作(实用程序Node.js 的函数借用了 Django 中的一些有用的概念)。
请参阅此处的文档。
I have done some work on a pretty complete port of the Django template language for Simon Willisons djangode project (Utilities functions for node.js that borrow some useful concepts from Django).
See the documentation here.
我将 Twig 与 Symfony 一起使用,现在涉足 Node.js,所以我正在查看 https://github .com/justjohn/twig.js 和 https://github.com/paularmstrong/swig,如果您使用 django,您可能会喜欢它。
I use Twig with Symfony and am now dabbling in node.js, so I'm looking at https://github.com/justjohn/twig.js and https://github.com/paularmstrong/swig, which you'll probably like if you use django.
如果您正在寻找一种简约的模板方法,可以查看 JSON 模板 。
功能更齐全的替代方案是 EJS。它与您从 Django 获得的东西有点相似。
对于其中每一个,您的情况可能有所不同 - 它们是为浏览器 Javascript 环境而不是 Node.js 设计的。
If you're looking for a minimalist approach to templates, you can check out JSON Template.
A more full-featured alternative is EJS. It's a bit more similar to something you'd get from Django.
Your mileage may vary for each of these - they're designed for a browser Javascript environment, and not Node.js.
警告:JinJs 不再维护。它仍然可以工作,但与最新版本的express不兼容。
您可以尝试使用jinjs。它是 Jinja 的一个端口,Jinja 是一个非常好的 Python 模板系统。您可以像这样使用 npm 安装它:
在 template.tpl 中:
在 template.js 中:
输出将是:
我们正在积极开发它,很快就会有一个好的文档。
WARNING : JinJs is not maintained anymore. It is still working but not compatible with the lastest version of express.
You could try using jinjs. It is a port of the Jinja, a very good Python templating system. You can install it with npm like this :
in template.tpl :
in your template.js :
The output will be :
We are actively developing it, a good documentation should come pretty soon.
haml 是 Node.js 的不错选择
http://github.com/creationix/haml-js
haml-js
html
haml is a good choice for node.js
http://github.com/creationix/haml-js
haml-js
html
我听说过有关 {dust} 的好消息 http://akdubya.github.com/dustjs/#dust
I've heard good things about {dust} http://akdubya.github.com/dustjs/#dust
尝试“vash” - 像 Node.js 的 razor 语法一样的 asp.net mvc
https:// github.com/kirbysayshi/Vash
还可以签出:http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
Try "vash" - asp.net mvc like razor syntax for node.js
https://github.com/kirbysayshi/Vash
also checkout: http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
Google 的 Closure Templates 是一个原生 JavaScript 模板系统,看起来与 NodeJS 很自然地契合。 以下是一些集成它们的说明。
Google's Closure Templates is a natively-JavaScript templating system and a seemingly natural fit with NodeJS. Here are some instructions for integrating them.
您尝试过 PURE 吗?
如果您尝试一下,请随时发布任何内容您在论坛中可能遇到的问题
虽然它主要是为浏览器,它与 Jaxer 和 Rhino 配合良好。
我还不了解node.js,但是如果你可以在内存中缓存一些JS和函数,速度应该会更令人印象深刻。
Did you try PURE ?
If you give it a try, feel free to post any trouble you may face at the forum
While it was primarly designed for the browser, it works well with Jaxer and Rhino.
I don't know node.js yet but if you can cache some JS and functions in memory, the speed should be even more impressive.
Django 模板引擎有一个到 JavaScript 的端口。不过,它已经很长时间没有更新了,但它可能仍然有足够的功能。
http://code.google.com/p/jtl-javascript-template/< /a>
There is a port of the Django templating engine to JavaScript. However, its not been updated for a long time but it may still have enough features.
http://code.google.com/p/jtl-javascript-template/
也尝试Yajet。 ;-) 这是我昨天刚刚发布的一个新工具,但我现在已经使用它一段时间了,它稳定且快速(模板被编译为原生 JS 函数)。
尽管代码量很小(缩小后为 8.5K),但它具有 IMO 模板引擎可能的最佳语法和丰富的功能集。它具有允许您引入条件、迭代数组/哈希、定义可重用模板组件等的指令。
Try Yajet too. ;-) It's a new one that I just released yesterday, but I'm using it for a while now and it's stable and fast (templates are compiled to a native JS function).
It has IMO the best syntax possible for a template engine, and a rich feature set despite its small code size (8.5K minified). It has directives that allow you to introduce conditionals, iterate arrays/hashes, define reusable template components etc.
我从 Twitter 上找到了 hogan.js,并由 Tim O'Reilly 在他的网站上推荐。我没有最佳实践,但我信任 Twitter 和 O'Reilly。你应该尝试...
I found hogan.js from Twitter and recommended by Tim O'Reilly on his site. I have no best practice with it, but I trust on Twitter and O'Reilly. You should try...