Jan 7, 2008

Javascript template engine : why and which ?

  1. Introduction
  2. State of art
  3. The choice
  4. Playing around

Hi there, as I needed a template engine for one of my customer, I looked around to find the one that was the best fitting my needs. My requirements where the following :

  • Cross-browser
  • Easy to learn
  • Allow easy internationalization
  • Library independent
  • Well documented and maintained
  • Possibility to add custom helpers and modifiers
  • Process relies on a compilation (to avoid multiple compilation)

Well, let's see what's on the place.

Table of content

Several client side templates engines are available, here are some that kept my attention :

Table of content

I finally decided to use JST that seemed to be the one that best fits my needs. MModifiers are simple to declare and to use for variables modification (such as upper-case or html sanitize-ing), and macros seems to be the way to declare helpers.
For the Internationalization, as I am using JSON datas it seems to be a simple workaround that can be achieved using a little layer aver the templateObject.

An other point that kept my attention is that syntax is most likely the same as the Javascript one, and that's a good point not to have to learn a new syntax.
Last but not least, it is possible to use inline JavaScript statements.

Table of content

Here comes the interesting part, it's time for tests ;-)
I'll keep you in touch with further posts including some of my code, but for now, I'll just give the documentation link

Table of content

No comments: