5. Applying Server-Side Includes
In some ways, the server-side include (SSI) is the
predecessor of the Dreamweaver Library item. The difference between
them is that Dreamweaver updates the Web pages with Library items at
design time, whereas the server handles the updating with server-side
includes at runtime (when the files are actually served to the user).
Server-side includes can also include server variables, such as the
current date and time (both local and Greenwich Mean Time) or the date
on which the current file was last saved.
The Related Files bar makes it much quicker to
modify SSI files. Server-side includes linked in the source
automatically appear in the Related Files bar. Just click the link to
edit immediately in Code view. Start up Live view to see your
modifications take effect instantly.
|
|
Because server-side includes are integrated in the
standard HTML code, a special file extension identifies pages using
them. Any page with server-side includes is most often saved with
either the .shtml or .shtm extension on Unix servers and .asp or .aspx on Windows servers. When a server encounters such a file, the file is read and processed by the server.
Not all servers support server-side includes. Some
Web-hosting companies disable the function because of potential
security risks and performance issues. Each .shtml page
requires additional processing time, and if a site uses many SSI pages,
the server can slow down significantly. Be sure to check with your Web
host as to its policy before including SSIs in your Web pages.
|
|
Server-side includes are often used to insert header or footer items into the <body>
of an HTML page. Typically, the server-side include itself is just a
file with HTML. To insert a file, use SSI code like the following:
<!- #include file="footer.html" ->
Note how the HTML comment structure is used to wrap
around the SSI directive. This ensures that browsers ignore the code
but servers do not. The file attribute defines the pathname
of the file to be included, relative to the current page. To include a
file relative to the current site root, use the virtual attribute, as follows:
<!- #include virtual= "/main/images/spaceman.jpg" ->
As evident in this example, you can use SSIs to include more than just HTML files — you can also include graphics.
With Dreamweaver's translator mechanism, server-side
includes are visible in the Document window during the design process.
In Dreamweaver, server-side–include translation is now automatic as
long as the Show Contents of Included File option, found in the
Invisible Elements category of Preferences, remains enabled.
One of the major benefits of SSIs is that
information can be inserted from the server itself, such as the current
file size or time. One tag, <! - #echo - >, is used to define a custom variable that is returned when the SSI is called, as well as numerous environmental variables. An environmental variable is information available to the server, such as the date a file was last modified or its URL.
Table 1 details the possible server tags and their attributes.
Table 1. Server-Side–Include Variables
Tag | Attribute | Description |
---|
<! - #config -> | errmsg, sizefmt, or timefmt | Used to customize error messages, file size, or time and date displays |
<!- #echo -> | var or environmental variables such as last_modified, document_name, document_url, date_local, or date_gmt | Returns the specified variable |
<!- #exec -> | cmd or cgi | Executes a system command or CGI program |
<! - #flastmod -> | file or virtual | Displays the last modified date of a file other than the current one |
<! - #fsize -> | file or virtual | Displays the size of a file other than the current one |
<! - #include -> | file or virtual | Inserts the contents of the specified file into the current one |