Mustache.js和Handlebars.js有什么区别? [英] What are the differences between Mustache.js and Handlebars.js?
问题描述
- Handlebars添加了
#if
,#unless
,#with
和#each
- Handlebars添加助手
- Handlebars模板已编译(Mustache也可以)
- Handlebars支持路径
- 允许使用
{
-
Handlebars.SafeString()
(以块形式输出当前项的字符串值){this}} >(可能还有其他一些方法)
- 把手是 2加快速度7倍
- 胡须支持倒置部分(即
if!x ...
)
- 把手是 2加快速度7倍
(请纠正我,如果我错了上述。)
有没有其他的m我缺少的主要区别是什么?
你几乎已经完成了它,然而胡须模板也可以被编译。 >
小胡子缺少帮手和更高级的方块,因为它试图无逻辑。 Handlebars的自定义助手可能非常有用,但通常最终会在您的模板中引入逻辑。
Mustache有许多不同的编译器(JavaScript,Ruby,Python,C等)。 )。 Handlebars以JavaScript开始,现在有像 django-handlebars ,handlebars.java , handlebars-ruby , lightncandy(PHP)和 handlebars-objc 。
Major differences I've seen are:
- Handlebars adds
#if
,#unless
,#with
, and#each
- Handlebars adds helpers
- Handlebars templates are compiled (Mustache can be too)
- Handlebars supports paths
- Allows use of
{{this}}
in blocks (which outputs the current item's string value) Handlebars.SafeString()
(and maybe some other methods)- Handlebars is 2 to 7 times faster
- Mustache supports inverted sections (i.e.
if !x ...
)
(Please correct me if I'm wrong with the above.)
Are there any other major differences I am missing?
You've pretty much nailed it, however Mustache templates can also be compiled.
Mustache is missing helpers and the more advanced blocks because it strives to be logicless. Handlebars' custom helpers can be very useful, but often end up introducing logic into your templates.
Mustache has many different compilers (JavaScript, Ruby, Python, C, etc.). Handlebars began in JavaScript, now there are projects like django-handlebars, handlebars.java, handlebars-ruby, lightncandy (PHP), and handlebars-objc.
这篇关于Mustache.js和Handlebars.js有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!