What are the differences between Mustache.js and Handlebars.js?

前端 未结 8 1489
心在旅途
心在旅途 2020-12-07 06:34

Major differences I\'ve seen are:

  • Handlebars adds #if, #unless, #with, and #each
  • Handlebars adds h
相关标签:
8条回答
  • 2020-12-07 07:30

    One more subtle difference is the treatment of falsy values in {{#property}}...{{/property}} blocks. Most mustache implementations will just obey JS falsiness here, not rendering the block if property is '' or '0'.

    Handlebars will render the block for '' and 0, but not other falsy values. This can cause some trouble when migrating templates.

    0 讨论(0)
  • 2020-12-07 07:32

    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.

    0 讨论(0)
提交回复
热议问题