Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm looking at backbone.js and noticed that it supports various templating systems (they specifically refer to Mustache.js, Haml-js, and Eco, but I understand it can support even more)(like Pure and dust.js)

My question is really why are there so many of these? What makes one better or different to the others? Can anyone shed light on what their individual strengths and weaknesses are.

share|improve this question
2  
Matter of preference, syntax and ease of use, functionalities provided (e.g. embedded JS execution or not etc.). It'll be very difficult to give a complete breakdown of all, but these are the dimensions of comparison IMHO –  PhD Aug 23 '12 at 17:16
add comment

3 Answers

up vote 8 down vote accepted

Here's a link to a LinkedIN Article where they detail their comparison and present their results as well as why did they select what they did (dust.js). This should give you some fair idea about the comparisons and what people are most likely to look for in templating solutions on client side and what are their strengths/weaknesses in those areas.

share|improve this answer
add comment

PhD already answered really well the comparison points, so I am gonna focus on

Why are there so many of these?

Quite a few reasons :

  • They have different philosophy concerning what should be in a template. Some try to force the "no logic in a template" rule, other don't care : For example, mustache is very strict, underscore let you use any sort of javascript in the template.
  • They were made by different people who had different need. Some wanted a very generic template system implementable in any language, other only needed javascript and optimised for that.
  • Some only needed the template to generate HTML, and optimized the syntax for that. Other made them capable of outputting any text content, but with a syntax that could be considered less confortable.

It all boil down to the definition of design: "Design is the art of balancing conflicting requirements". People who designed the various template engine had different priorities, so they produced different designs.

share|improve this answer
2  
Don't forget to include a healthy dose of NIH. Template systems are relatively easy to write so many people think they can write their own & make it better. –  Sean McSomething Mar 14 at 0:21
    
Oh, so true :) . –  Laurent Bourgault-Roy Mar 14 at 15:36
add comment

I'm currently going for Mustache.

The main reason, is that it's available in Ruby, JavaScript, Python, Erlang, node.js, PHP, Perl, Objective-C, Java, .NET, Android, C++, Go, Lua, ooc, ActionScript, ColdFusion, Scala, Clojure, Fantom, CoffeeScript, D, Haskell, XQuery, ASP, Io, Dart, and Haxe.

This means you can share your templates between your JS and whatever backend language you're using, which is very useful if you want to render your layout in backend and rerender it in frontend when updating. While some other template systems also have implementations in other languages than their initial implementation, Mustache is the only one with multiple official implementations.

Mustache templates also have a very simple syntax that don't add much clutter to your HTML and actually still look like HTML (unlike HAML).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.