Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 953
Chad Johnson Avatar asked May 11 '12 17:05

Chad Johnson


People also ask

What is Mustache js used for?

Mustache can be used for HTML, config files, and source code. It works by expanding tags in a template using values provided in a hash or object. You can use Mustache to render templates anywhere include client side and server side environments.

Is handlebars a superset of Mustache?

In general, the syntax of Handlebars. js templates is a superset of Mustache templates. For basic syntax, check out the Mustache manpage.

What is handlebars in js?

Handlebars. js is a Javascript library used to create reusable webpage templates. The templates are combination of HTML, text, and expressions. The expressions are included in the html document and surrounded by double curly braces.

Which programmatic language uses handlebars and Moustache style syntax?

js is self-described as: Handlebars. js is an extension to the Mustache templating language created by Chris Wanstrath.


1 Answers

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.

like image 182
frontendbeauty Avatar answered Sep 30 '22 22:09

frontendbeauty