To read the article online, visit

Enhancing Web Site Maintainability using Templates, Part 2

By Christiaan Verwijs

Read my first article? The one about the templates? Well, this article is part 2 in a serie of articles about template-aided design. A method I use on my own site.

In the previous article I explained the basics of my site-building method, and how to write your own scripts to use it for your site. If you havenít read the previous article, make sure to do so before you start reading this one!

Ready? Letís get on with it!

The method discussed in my first article can greatly improve maintainability and flexibility. However, there was one big downfall. Because the templates and data were both stored in a database, it was not possible to use ASP-scripts within the template. You can try it yourself Ė ASP in a database just isnít going to work. In this article I will discuss a method to allow us to use some functions to format the data entered into the template-slots (in case you forgot: a slot is a number enclosed in two block-quotes which is replaced with data during the compilation of the template). Now, we will never be able to use ASP in the database, but what if we can place parameters in the template which tell the ASP template-compiler what to do with the data before placing it in the template?

This is the template we used in the previous article:

<FONT FACE=ĒverdanaĒ SIZE=Ē1Ē><B>[1]</B> - [2]<FONT>

Now, wouldnít it be nice to be able to limit the number of characters displayed in a slot, or to tell the server to first remove HTML-code from the data-to-be-inserted? Or perhaps to format the data as currency or as date-time?

Well, itís possible if we alter our template a bit:

<FONT FACE=ĒverdanaĒ SIZE=Ē1Ē><B>[1|50|FALSE]</B> - [2|0|TRUE]<FONT>

In this new template, Iíve defined two special parameters for each slot (excluding the slotís ID-code). The first parameter specifies the maximum number of characters to display in that specific slot (0 = no limit). The second parameter specifies whether or not the server should remove HTML-code from the data (for my site, Iíve made a special formatting-language called EML, and this tag specifies whether or not to use it Ė perhaps Iíll share the scripts behind this language with the world somewhere in the future).

Strictly speaking, you can replace these parameters with whatever you want, itís also possible to add more parameters, but thatíll require some tuning of the script displayed below.

Ok, so the template now supports slot-parameters, but how do we get the ASP-script to actually do what the parameters dictate? Before giving you the script I used, Iíll explain exactly the proces behind it.

The first thing we want, is an array filled with the data we want to put in the template. I recommend using GetRows (technical docs) as shown in the previous example. This array should be 2-dimensional; the first dimension holds the number of the record, where the 2nd dimension holds the individual column-values for that record. In the case of this table:

O. JacksonWisconsin, USA29
C. WagenmakerAmsterdam, NL16
O. HeinrichBerlin, GER63

The Array-record with address (0, 0) would refer to the value O. Jackson, address (1, 0) would refer to Wisonsin, USA and (2, 1) to 16.

Now that we have a array filled with data, we can start compiling templates.

The next step in the proces is to isolate the individual slots and to analyze them. Each slot will, again, be split into its individual parameters so that we can use them later one. Now, the only thing left to do, is to cycle through the slots in the template and to replace them with (when specified - formatted) data. This proces is repeated for every record so that you end up with a whole bunch of compiled templates (1 for each record). This is also the resulting value of the function.

In Part 3 we will look at the script to compile a template!

  • Read Part 3
  • Read Part 1

  • Article Information
    Article Title: Enhancing Web Site Maintainability using Templates, Part 2
    Article Author: Christiaan Verwijs
    Published Date: Monday, February 14, 2000
    Article URL:

    Copyright 2019 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers