When AJAX started to hit hard, at the end of 2005 I wrote a template engine on the client side and basically turned my blogger template into a full-fledged AJAX experience.
The fact is that this template material was really easy to implement, and it eliminated most of the grumbling work.
Here is how it was done.
<div id="blogger-post-template"> <h1><span id="blogger-post-header"/></h1> <p><span id="blogger-post-body"/><p> <div>
And then in JavaScript:
var response = // <- AJAX response var container = document.getElementById("blogger-post-template"); if (!template) { // template context template = container.cloneNode(true); // deep clone } // clear container while(container.firstChild) container.removeChild(template.firstChild); container.appendChild(instantiate(template, response));
The instance function makes a deep clone of the template, and then searches for a clone for identifiers to replace with the data found in the response. The end result is a populated DOM tree that was originally defined in HTML. If I had more than one result, I just got stuck in the code above.
source share