You can create a system of scripts and templates to generate Web pages that share a look and feel. Starting from the basics, here's a description of how I created a script and template system for generating web pages:
- First, I created an HTML template for the overall look and
feel for a typical page of my web.
In place of titles and strings of information which may
change from page to page, include parameters of the
form
XX-string
, wherestring
is some identifier such asTITLE
,ANNOTATION
, orDATE
.For example, I created this template for personal files on my web site. Notice that it has parameters:
XX-TITLE
,XX-ANNOTATION
,XX-CONTENT
,XX-FILE
, andXX-DATE
. - I broke up this HTML template into two files at the
XX-CONTENT
line, leaving this line out of both files: name one as head file and the other as foot file.For example, here's the
johnhead.html
andjohnfoot.html
files. - I made a script to sandwich a file of content between
this head and foot file.
For example, here's the
makejohn1.0
Unix script to sandwich a contents file between the header and footer file.I create a directories "bin" to hold my scripts, "src" to hold my header, footer, and contents files, and "gen" to hold the generated files. For every file in my directory, I don't store header or footer information, just the content in the
src
directory. For example, I place myhobbies.html
file, without header or footer information insrc
.I ran the
makejohn1.0
script with the content filehobbies.html
as its parameter:$ makejohn1.0 hobbies.html
makejohn on hobbies.html
generated in ../gen/hobbies.htmlI've improved my implementation system one order of abstraction over a template method because I'm no longer tied to a fixed header and footer for each file. I can always switch headers and footers and regenerate the file. I could move the generated file from
../gen
to the Web server space, or I could just generate the file with the GENLOC variable set in my script to the appropriate place.However, the
XX-
information is still in the generated file. I could replace this by hand in each generated file, but then this would be work that I'd have to repeat if I change my head or footer styles later on. - The script
makejohn1.1
parameterizes theXX-
information. It takes three arguments: the filename, the title, and the annotation and generates the HTML file, replacing theXX-
strings:$ makejohn1.1 hobbies.html "My Hobbies" "These are things I do when I have some spare time..."
makejohn on hobbies.html My Hobbies These are things I do when I have some spare time...
generated in ../gen/hobbies.htmlThe result is that I have enforced a look and feel and have parameterized the variations from file to file. I create a
makejohnweb
script to contain the call to themakejohn1.1
script so that I can add more lines tomakejohweb
as I develop more content files, such as:makejohn1.1 resume.html "Resume" "Education and work experience"
makejohn1.1 faq.html "FAQ" "These are questions (with answers) that I frequently receive by email..." - I can create another level of abstraction by parameterizing the style of the
header and footer.
I create a makestyle script which has
has an additional arguments for style.
This script requires that I have style files prepared.
For example, I create
bookhead.html
,bookfoot.html
, and a "bare" contents file,src/hcu.html
Then I can generate a "book style file":$ makestyle hcu.html book "HTML and CGI Unleashed" "This book helps you in all stages of Web development"
makestyle on hcu.html book HTML and CGI Unleashed This book helps you in all stages of Web development
generated in ../gen/hcu.htmlI can collect similar book style generation lines in a
makebookweb
script.
This technique can become more sophisticated and powerful as you make your scripts more elaborate and parameterize more elements of your web's style.
With some more creative changes, I could parameterize the XX- strings I include in the header and footer files. I could have "cascading styles" where a particular style borrows elements from several other styles--perhaps the head from one style, the foot from another.
Eventually, style sheets in HTML may be able to implement many of the look and feel decisions that I'm currently placing in the header and footer files and scripts. If so, I can modify my scripts to generate these style sheets and put that style information in HTML elements in the head and foot file. In fact, I could use different generation techniques to generate a text-only version of my web, a frames version, or a version with only particular HTML elements--it is simply a matter of changing my scripts or the head and foot files.
See the HTML Toolbox for software that can help you build Web pages.