When comparing Handlebars.js vs Haml, the Slant community recommends Handlebars.js for most people. In the question“What are the best HTML preprocessors?” Handlebars.js is ranked 3rd while Haml is ranked 4th. The most important reason people chose Handlebars.js is:
Handlebars is available as a JavaScript library, a [Django](https://github.com/yavorskiy/django-handlebars) module as well as [Java](https://github.com/jknack/handlebars.java), [Ruby](https://github.com/MSch/handlebars-ruby), [Scala](https://github.com/mwunsch/handlebars.scala), [.Net](https://github.com/rexm/Handlebars.Net) & [PHP](https://github.com/zordius/lightncandy) libraries, which means you can use it for frontend and backend templating in the language of your choice.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Clean syntax
Handlebars's syntax is very readable and easy to understand.
Pro Clear separation of logic and markup
If something is not within {{
and }}
, it's not Handlebars. As a result, Handlebars "weaves" through HTML, instead of trying to become an invalid extension of it.
Pro Copy/Paste code from the internet
Examples for Bootstrap or other CSS frameworks are always in HTML. With Handlebards you can just copy and paste the examples in your code. With something like Pug (Jade) you have to convert the HTML to Pug (Jade) first.
Pro Easy to use for templating things other than HTML
The syntax allows the output to be any text and does not contrain the user to HTML output only. There are examples of handlebars being used to produce SQL, javascript and other programming language code.
Pro Easy to use any template also as partials
Templates may be nested and reusable parts can be factored out.
Pro Compiled rather than interpreted templates
Handlebars.js allows you to pre-compile your templates so that the loading time at the client end could be reduced when your templated page is loaded.
Pro Mustache compatible
You can import Mustache templates and add extra functionality, that's provided by Handlebars, on top of them.
Pro Good global helpers support
Pro Logic-less
By design, logic-less templates force you to separate concerns thus helping you avoid future problems with refactoring. It also allow templates to be used with multiple programming languages without changes.
Pro Good paths support
With Handlebars.js you can create bindings with variables inside any path in your application.
Pro Easy to define extensions
With a few lines of code, a new extension (control or templating function) can be implemented. It will be called by the compiled templates.
Pro Easy to learn
There are plenty of learning resources available for those who want to learn Haml. The documentation is detailed and well organized, and Haml is easy to pick up.
Pro Efficient
By using indentation rather than closing tags and eliminating curly braces, Haml is fast to code.
For example
This:
<div id ="lower">
<div class="right column">
<div id="currentDate"><%= print_date %></div>
</div>
</div>
Can be written as:
%div#lower
%div.right.column
%div#currentDate= print_date
Pro Clean syntax
Haml's syntax is very clean and pleasant to look at. It doesn't use HTML tags and it's not verbose at all. The templates are easily readable.
Cons
Con Hard to use documentation
Although the documentation exists and is fairly comprehensive, it's not always clearly written, and there is no search capacity.
Con Handlebars are still an HTML code
Handlebars use the standard HTML syntax with its own {{tags}} for templating. This doesn't add much to readability or design speed.
Con Using partials is cumbersome
"In order to use a partial, it must be registered" using some JavaScript method attached to some global variable.
Con Not much editor support
Handlebars.js doesn't seem to have many text editors that support things like auto-complete, syntax highlighting or error checking for it.
Con Does not play well with Angular.js
.. or any framework where you wish to compile handlebars.js template to the template understanable by the framework.
Con Bad Performance
The rendering time with haml is slower than its competitors.
Con Whitespace sensitivity can be problematic
Haml uses indentation to define structure, rather than closing tags. Though this, in most cases, makes code more efficient to write, it can also cause problems.
Being off by one space can cause an error or change the structure of the code.