What templates are and how
to use them
[Contents]
Imagine you are writing a CGI program that outputs a HTML page informing the user that their membership request has been accepted and gives them their membership number. You might use the following code to output your page:
CGI.ContentType:=ctHtmlPage;
CGI.StartSend;
CGI.Send('<BODY
BACKGROUND="/images/back.jpg">');
CGI.Send('<TABLE WIDTH=100% BORDER=0>');
CGI.Send('<TR><TD WIDTH=20></TD><TD>');
CGI.Send('<CENTER><IMG
SRC="/images/cc1.jpg"></CENTER>');
CGI.Send('<b><FONT SIZE=5
FACE=ARIAL>Complete</FONT></b><br>');
CGI.Send('Your membership has been accepted.<p>');
CGI.Send('Your membership number is ' +IntToStr(MemberNumber);
CGI.Send('<center><A HREF="/"><IMG
SRC="/images/back2.jpg"
BORDER=0"></A></center>');
CGI.Send('</TD></TR></TABLE>');
The only thing that changes is the Member Number. Sending the output like this is tedious and means that the CGI program has to be edited and recompiled every time you change the style or layout conventions of your site. Also, you can't use a HTML editor such as FrontPage to create your HTML.
This is where templates come in. A template is just a normal HTML file saved on the web server. The file can contain 'variables' which are enclosed in tildas (~). So for example, a template for the above might be saved in 'NEWMEMBER.HTM' and would look like this:
<BODY
BACKGROUND="/images/back.jpg">
<TABLE WIDTH=100% BORDER=0>
<TR><TD WIDTH=20></TD><TD>
<CENTER><IMG
SRC="/images/cc1.jpg"></CENTER>
<b><FONT SIZE=5
FACE=ARIAL>Complete</FONT></b><br>
Your membership has been accepted.<p>
Your membership number is ~MEMBERNUMBER~
<center><A HREF="/"><IMG
SRC="/images/back2.jpg"
BORDER=0"></A></center>
</TD></TR></TABLE>
You can use the CGI component to read in this template, and send it to the web browser, replacing the variables with values you choose. You do this using the SendHTMLFileVar method.