You might have noticed how this website maintains a standard-looking appearance throughout it, and might be wondering how I maintain this template-ish format. The answer for me did not lie in writing PHP, Perl, using databases, or using complicated Apache modules to achieve this effect. It’s all done fairly simply with Server Side Includes (SSI’s).
A poster on Slashdot suggested the method I’m using: separate the content from the surrounding information. This is achieved by having three files for any particular page I want to create: the content file, the template file, and the settings file.
I’m going to walk you through how an example page, my Opinion page is created. Note that I have my Apache install set to have Server Side Includes enabled for files ending in .html
The Content File
The content file contains the content for a
particular page; this information is generally what is found in the body
of an HTML page, between the
body tags. Note our example content
file contains only HTML related directly to the
content; there is no header information in this file. I use the suffix
of .src.html for these files, to indicate they are only the content of
an HTML page, without the full headers and such.
The Settings File
The settings file is the one that is actually referenced by the URL in a person’s browser. It is very small; all it does is set some variables for use by the content file or the template file, such as the title and the location of the `content file, and then it simply includes the template file. Generally, this file is the index.html file for a particular directory.
The Template File
The template file provides the overall layout for all the pages that use that template, saying what sort of information gets put where, and providing HTML header information, such as the title. This template file is used for all pages on the site; it uses variables set by the content file or itself to reference small pieces of information that are specific for each page, such as the title, and the location of the content. however, in practice my template has a suffix of .html.
Putting it all together
That’s it! The finished product incorporates all three parts, to present the final page.