Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript template framework [closed]

I am writing a lot of web applications that requires a lot of dynamic content that is replaced according to various ajax request to the PHP+mySQL backend that is able to respond all data as JSON. This could be something like quizzes, polls or it could also be more advanced applications that requires more updates of the DOM. The point is that the integration with the HTML (wich is coded by a third part) is as easy as possible.

Since this are many small applications and not a big site, I am looking for a library that helps me get the job done fast and easy to customize later on. I don't know the best way of doing this but know that there are various libraries out there that does what I need (and a lot more).

Required features:

  • Lightweight
  • Easy to update the HTML structure (even for HTML-only coders)
  • Compatible with jQuery
  • Works with all modern browsers including Chrome, Firefox, Safari and IE7+
  • Works with all mobile browsers including Android, iOS and Windows Mobile
like image 288
jack Avatar asked Mar 16 '12 23:03

jack


2 Answers

I would try Distal.

You said your HTML is coded by a third party so you would want minimal changes during integration. With distal you add stuff to the existing HTML and don't need to move things around.

The syntax is HTML based so it's suitable for HTML only coders.

like image 112
Kernel James Avatar answered Sep 19 '22 01:09

Kernel James


Mustache is pretty solid, but I found it to be a little too hardline about the "logicless template" thing. For example, it doesn't offer a lot of small niceties you'd hope for in a templating system, like an "else" statement. You have to do dumb stuff like this all the time:

{{#if foo}}
    <span>foo is set</span>
{{/if}
{{^if foo}}
    <span>foo is not set</span>
{{/if}}

Instead, I'd recommend Handlebars which is built on top of Mustache, but adds some nice features like custom helpers and better context-switching support.

like image 42
nickf Avatar answered Sep 17 '22 01:09

nickf