Seb*_*Seb 271 javascript template-engine node.js
我正在尝试使用Node.js构建整个Web应用程序.是否存在类似于(例如)Django模板引擎等的模板引擎,至少允许您扩展基本模板?
mik*_*eal 52
您应该能够使用mustache.js,如果它不起作用,请将问题发送给我,我会解决它,因为我将要在node.js中使用它们.
http://github.com/janl/mustache.js
我知道它可以在没有DOM的情况下工作,因为一堆CouchDB独立应用程序正在Spidermonkey视图服务器中使用它.
小智 40
如果你喜欢haml,但想要更好的东西,请查看http://jade-lang.com节点,我也写了haml.js :)
Nos*_*dna 15
有新的模板引擎.
underscore.js为js添加了许多函数式编程支持,并具有模板性.
就在今天我听说过:http://github.com/SamuraiJack/Shotenjin-Joosed
Fab*_*obs 13
您应该看一下node-asyncEJS,它明确地设计为将node.js的异步特性考虑在内.它甚至允许模板内部的异步代码块.
这里是一个文档的示例:
<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>
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以尝试无胡须(它的灵感来自焊接/板):
例如:
{ 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..."} ]
}
}
Run Code Online (Sandbox Code Playgroud)
你的模板:
<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>
Run Code Online (Sandbox Code Playgroud)
输出:
<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>
Run Code Online (Sandbox Code Playgroud)
我已经为Simon Willisons djangode项目的一个非常完整的Django模板语言端口做了一些工作(node.js的Utilities函数从Django借用了一些有用的概念).
请参阅此处的文档.
我在Symfony上使用Twig,现在正在尝试使用node.js,所以我正在查看https://github.com/justjohn/twig.js和https://github.com/paularmstrong/swig,你会可能就像你使用django一样.
警告:JinJs不再维护.它仍在工作但与最新版本的Express不兼容.
你可以尝试使用jinjs.它是Jinja的一个端口,是一个非常好的Python模板系统.您可以使用npm安装它,如下所示:
npm install jinjs
Run Code Online (Sandbox Code Playgroud)
在template.tpl中:
I say : "{{ sentence }}"
Run Code Online (Sandbox Code Playgroud)
在你的template.js中:
jinjs = require('jinjs');
jinjs.registerExtension('.tpl');
tpl = require('./template');
str = tpl.render ({sentence : 'Hello, World!'});
console.log(str);
Run Code Online (Sandbox Code Playgroud)
输出将是:
I say : "Hello, World!"
Run Code Online (Sandbox Code Playgroud)
我们正在积极开发它,很快就会有一份好的文档.
归档时间: |
|
查看次数: |
136000 次 |
最近记录: |