![]() |
|
|
Published: Friday, February 04, 2000 By Christiaan Verwijs Before I start: This article describes a website-building method you can use. The scripts here are not copy-paste scripts, but show you how to use the method.
Most people use ASP primarily to mould data taken from a database into a pre-written template. That is, they create a Web page to output the contents in a particular database table. This allows far greater flexibility and maintainability than hard coding values into a Web page because the data in the database can be changed using an online-form. Now, there's one big limitation to this method - the template used in the Web page to output and format the database record is not dynamic. Once it's online, it's rather difficult to change it. Besides, editing the template can only be done by people with knowledge of ASP, and when your site has a rather big staff, you can be sure that most of them do not know how to use it - resulting in you having to do it. I came across this problem when building a site with a staff of over 10 people. The only person able to use ASP was me. However, I wanted to allow everybody to change the templates - and preferably through an online-form. Another reason for this 'project' was that I wanted to be able to truly reuse a template on a different page without having to copy the HTML/ASP-code to that page. I wanted to be able to use the exact same template for every page - this allowed me to change a whole bunch of pages by changing one of the templates used on the pages.
I had several choices, I could use the Now, some of you may wonder how I got this to work? After all, it's not possible to store ASP-scripts in a database. Indeed, ASP wasn't a choice here, I had to come up with a way to store the template in the database but maintain the dynamic nature. Before I start throwing scripts at you, let me explain the basics of my approach: Basically, a template is nothing more than a piece of HTML-code with special 'slots' where data can be dynamically entered. Usually, you would use ASP-code to build these slots. But in my case, since use of ASP wasn't possible here, I chose for another type of 'slots'. Take a look at this example
This is a normal ASP-template. The template can display both the name and the address of a person or whatever you want. I chose to change the slots, turning the template into this:
A template like this can be stored in a database. It doesn't contain any ASP-code. But how did I get the server to insert the (dynamic) data into the slots? Well, this may be a bit technical, so hang in there.
I used
The output of this script can be:
This script is just a small example. To keep things easy, I defined the template-to-use within the function
(the string Using this method can greatly enhance maintainability, but there are some things you should take into consideration:
There are some other things you will propably run into when using this method, but most of them can be solved pretty well I think. It just depends upon how complex you want to make the function building the templates. On my site (which is not yet online), I've placed the templates in a database, as well as the data used to build the real HTML-code using these templates. In addition, I made a variety of templates for each page, so that visitors can chose the template they like best. And most of all, the staff can now edit the templates without requiring my assistance. I, myself, have made a quite advanced version of this method. My engine (as I like to call it), can also cache templates by storing a pre-compiled version of the template + data in a special table. To increase speed, the engine can use a cached version instead of having to recompile the whole template and the data again. In addition, my engine also supports various advanced ASP-like functions for use within the template! For example: I can determine the number of characters to display, and how to format the data. But that's for the future .... Happy programming!! Questions, comments, suggestions? E-mail me at TekTronix@eveolution.com. Christiaan Verwijs is a 19-year old Business Information-Technologies student from the Netherlands. whenever he has time left, he works on his own gaming-site (http://www.eveolution.com) which will be launched somewhere within the next 4 months. He learned how to use ASP in less than 8 months - all thanks to 4Guys.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||