A Better JavaScript Template Engine

7

Posted on : 08/25/2008 | By : Jimmy Vu | In : Solution

Rizqi Ahmad from Germany has introduced a nice solution for client-side template based on JQuery. The Chain.js allows you to use any piece of HTML (or embedded HTML string) as template to display data dynamically.

In introductory post, he went through some common approach like server-side data binding, injecting preformatted HTML (into well-known DOM property innerHTML) and directly manipulating DOM, then explained why Chain.js is better way:

  1. Easy and compact (as it uses JQuery for manipulating DOM)
  2. Preserve event(s) on updates
  3. Allow dynamically add/remove data

To use the engine, you’ll need to download JQuery (better the latest version) and Chain.js then add script tags to load them.

<script src="path/to/jquery.js" language="javascript"> </script>
<script src="path/to/chain.js" language="javascript"> </script>

Practical Example on Chain.js

Now, we’ll create a practical example that allows user select a programming language and display recommended reading books accordantly. This is almost similar to another example I created for PURE library.

First, build a template table to display book list:

Read the rest of this entry »

Recommended Reading

Store This! Simple Home Storage Systems & House Organization Solutions (Gleam Guru)Store This! Simple Home Storage Systems & House Organization Solutions (Gleam Guru)From the international bestselling author of 'Get Organized! Your 12 Month Home Clutter Killer Guide' comes this all new guide to home storage.
<... Read More >
The Beauty Detox Solution: Eat Your Way to Radiant Skin, Renewed Energy and the Body You've Always WantedThe Beauty Detox Solution: Eat Your Way to Radiant Skin, Renewed Energy and the Body You've Always WantedNutritionist and beauty expert Kimberly Snyder helps dozens of A-list celebrities get red-carpet ready—and now you're getting the star treatment. Ki... Read More >
Fair Trade? Its Prospects as a Poverty SolutionFair Trade? Its Prospects as a Poverty SolutionFair Trade is an enormously popular idea in Christian and secular circles alike. Who, after all, could be against fairness? Victor V. Claar, however, ... Read More >