A Complete Guide to Web Design

(やまだぃちぅ) #1
Adding SSI Commands to a Document 253

Server Side
Includes

Adding SSI Commands to a Document

Web Design in a Nutshell, eMatter Edition

If you focus on front-end web design, you can get started right away using the
elements and variables listed in this chapter, however, you may need to consult a
CGI programmer to design the back-end for more advanced SSI solutions.


SSI and the Server


It should come as no surprise that the function of SSI depends heavily on the
configuration of the server. This is another instance in which you need to commu-
nicate with your system administrator to find out whether your server supports SSI
and, if so, which syntax to follow.


The instructions in this chapter use SSI commands that work for NCSA HTTPd
Server Side Includes, and, specifically, those documented in the Apache server’s
mod_include module. Apache is a freely distributed and highly sophisticated
server software package that makes up a large percentage of servers on the Web.
NCSA, Netscape, and WebSite server software also support SSI without significant
configuration changes. The instructions and examples shown in this chapter may
not work with your server, so be sure to check with an administrator first.


Adding SSI Commands to a Document


Server Side Include commands have the following format:


<!--#element attribute="value" -->

Theelementis one of the predefined functions that Server Side Includes can
perform, such asinclude orecho (we’ll talk more about specific elements later).


The command also includes one or moreattribute/valuepairs that provide the
specific parameters to the function.


There are a few important things to note about SSI command syntax:



  • The whole command must be enclosed within comment indicators ().

  • The comment terminator (-->) must be preceded by a space to make it clear
    it is not part of the SSI information.

  • Keep the whole command on one line (line breaks between the comment
    tags may cause the SSI not to function).

  • The# symbol is an important part of the command and must not be omitted.


Example: Virtual Includes


The simplest type of Server Side Include is a “virtual include,” which tells the
server to add information to a file before sending it to the browser.


In this example, let’s take a page from within a web site that uses a standard navi-
gational toolbar held together with a table. Instead of placing the table in the
HTML source for every web page in the site, we could just insert it into each docu-
ment as follows:


<HTML>
<HEAD><TITLE>News</TITLE></HEAD>
Free download pdf