A Complete Guide to Web Design

(やまだぃちぅ) #1
254 Chapter 13 – Server Side Includes

Adding SSI Commands to a Document


Web Design in a Nutshell, eMatter Edition

<BODY>
<!--#include virtual="navtable.html" -->
<H1>Today's Headlines</H1>
... page contents...
</BODY>
</HTML>
Documents that contain SSI commands should be saved with an identifying suffix,
which indicates to the server that the file should be parsed before being sent to
the browser. In most cases, the suffix is .shtml(the default), however, this can be
configured to be any suffix, so check with your server administrator first.
The command in the above example uses theincludeelement, which inserts the
text of another document into the parsed file. Theincludeelement uses the
virtualparameter to specify the URL of the document to be inserted, in this
case,navtable.html. The following shows the entire contents (simplified for sake
of space) ofnavtable.html:
<TABLE>
<TR><TD><IMG SRC="toolbar.gif"></TD></TR>
...complicated toolbar stuff...
</TABLE>
Technically, this is just a fragment of an HTML document because the structural
tags (<html>,<head>, and<body>) have been omitted. This is one way to ensure
the final document doesn’t end up with a double (and conflicting) set of structural
tags. If you leave them in, be sure they match the parsed document exactly, and
keep in mind that double<body> tags aren’t received well by some browsers.
Many web masters (including the folks at HotWired) label these fragments with the
.htmlf suffix to keep them distinct from normal HTML documents, although it’s
not necessary.
The server puts the fragment in the spot indicated by the virtual include command.
When the document is sent to the browser, the source looks like this:
<HTML>
<HEAD><TITLE>News</TITLE></HEAD>
<BODY>
<TABLE>
<TR><TD><IMG SRC="toolbar.gif"></TD></TR>
...complicated toolbar stuff...
</TABLE>
<H1>Today's Headlines</H1>
... page contents...
</BODY>
</HTML>
Theincludeelement is just one of the elements available through SSI. The full
list of Apache 1.3 elements appears in the “List of Elements” section later in this
chapter.
Free download pdf