Reputation: 12399
What are some use cases for mustache?
I just discovered it today but I can't seem to understand how is it different from just creating regular template files in your framework (cakePHP, django, etc..) or just having an html + php file.
Upvotes: 2
Views: 1632
Reputation: 1598
One of the main attractions of Mustache to me is that there are so many implementations of it.
As a simple example, you might be creating a list of products.
Same template, reused both client-side and server-side. If you ever need to change the HTML you are only doing it in one place and it will be consistent with both server-side rendered and client-side rendered content.
Upvotes: 0
Reputation: 4918
Previous responses omit the fact that with a library as Mustache the entire page rendering is done client-side, whereas most template engine are aften used to render partials and formatting server-side.
The main use case I see for this library is to create web-apps based on JSON or XML webservices served from a server you don't have access to.
Upvotes: 0
Reputation: 3483
The whole point of Mustache is that it's logic-less. You pass it well-formatted JSON, and it does the rest in a super-simple syntax. The way this is different from PHP is that there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values. You don't have multiple arrays that you have to manage, just one javascript object that you set and forget and watch the page render.
More information/source: http://mustache.github.com/mustache.5.html
Upvotes: 2
Reputation: 160181
Mustache allows almost no intelligence in the view--separation of concerns is its usecase.
It is another template engine/library, the only (real) difference is in its syntax and philosophy.
Upvotes: 4