Archive of UserLand's first discussion group, started October 5, 1998.
Server side javascript as template engine
Author: Tommy Sundström Posted: 4/22/1999; 8:07:58 AM Topic: Server side javascript as template engine Msg #: 5189 Prev/Next: 5188 / 5190
Another aproach to template driven publishing:"Writing server-side JavaScript (SSJS) applications has been one of the more common tasks that we've performed within Netscape Germany's Worldwide Professional Services group. After some experiences with hard-coded user interfaces, we came across the View Source article Using Presentation Templates With Server-Side JavaScript: A Simple Way to Change an Application's Look and Feel Without Touching the Source Code. In that article, Glen Long describes a simple template engine, written entirely in JavaScript, that replaces special placeholder tags in HTML pages (of the form <%name%>) with a value that was defined by the SSJS application at run time. This mechanism enables the application logic to be separate from the presentation logic. To store the name/value pairs, Glen simply used the attributes of a JavaScript object.
Template engines are not a new invention, but writing one that's so simple in JavaScript demonstrated JavaScript's power - and it made our lives a whole lot easier. But as soon as we started to use Glen's template engine, we found several shortcomings in the implementation. Since everything was written in JavaScript, it was easy to change, so we enhanced it quite a bit, adding several useful features that made it even more valuable to us and easier to use. The result of our efforts is the JavaScript Template Engine (JSTE), which offers several new types of tags with these capabilities: including templates within templates; showing and hiding HTML based on conditions (with IF statements); and extending JSTE via JavaScript plug-ins. Plug-ins for generating HTML