views:

62

answers:

3

Recently, I found out that jQuery has an official template engine which was contributed by the Microsoft team. Also I had heard about jTemplate from my friends, but I'm still confused:

  1. When & where might I need to use these plugins?
  2. How should I choose between the many client side template engines?
+1  A: 

The reason for a jQuery template engine is this: developers write Javascript code to create new chunks of HTML to inject into the page. This usually is done by concatenating many strings with variables for values, and it becomes difficult to maintain.

With a jQuery template engine, the process of creating HTML at the client can benefit from all the same advantages that server-side developers now have with their templating engines.

Ned Batchelder
what confused me is where the data from,from server-side?so it's most useful for ajax application,but many application are use traditional technology
mlzboy
A: 

I'll address your first question.

You can store data in JavaScript objects (instead of SQL databases, for example). Those JavaScript objects can be stored in .js files, or inline as part of the HTML document. You can take a look at the source code of my w3viewer.com. All data is stored inside a JavaScript array.

In the example of my web-site, I dynamically create HTML lists with data taken from that JavaScript object (I generate the HTML code string). One could use templating to get this job done.

Šime Vidas
A: 

A template-engine prevents unnecessary HTML-code in the actual code. This makes it much easier to read.

Mzialla