|
Using SSI
All SSI commands are written in the form of <!--#command--> and placed inside a
standard HTML document with an extension of .shtml on the CGI-BIN server.
As you probably know, enclosing text between <!-- and --> tags causes it
to be treated as a comment by browsers and most HTML editors. Some of the more sophisticated
HTML editors will recognise SSI and in some cases parse it, others will just ignore it as a
comment. Either way, you do not need a special editor.
Do not forget to place the # symbol before the command itself, or it will be treated as
a comment.
The server doesn't care whether you use uppercase or lowercase characters for the command
itself, so you can use whichever suits you. Any filenames used will have to be referenced
correctly of course.
Including a file
There are two similar commands available to do this, the only real difference between them being
the way the path is handled.
<!--#INCLUDE FILE="local.txt" -->
This would include the contents of the file called local.txt at the point in the
document where the code was placed. A relative path is used to describe the location of the
file to be included - in this case the file is in the same directory as the document including
it.
This is most useful for content that is used for a particular section rather than a whole
site. Having a different version of local.txt in each directory would allow you to
use the same template for the whole site, yet still make each section different. An obvious
example is the code for a navigation menu specific to that directory.
<!--#INCLUDE VIRTUAL="/~username/global.txt" -->
This would include the contents of the file called global.txt at the point in the
document where the code was placed. An absolute path is used to describe the location of the
file to be included - in this case the file is in the root (public_html) directory for the
user called username.
This is most useful for content that is used in multiple sections throughout a site - such
as a site navigation menu or a copyright message.
If the file you are including contains HTML, it is still wise to name it with a .txt
extension. The reason being that it is not a complete HTML document, and should not be named
as if it were.
Some hosts also place banner code into any file with a .htm or .html
extension automatically, leading to multiple banners appearing on a single page. Using
.txt as an extension avoids this.
That is not a method of getting around displaying banners by the way, as the main
document containing the SSI code in would be named as an HTML document. I believe that if you
agreed to display a banner on each page when signing up for free hosting, then you should do so,
but it is obviously not in anyone's best interests to have multiple banners on a page.
If you are with a host that has this restriction, you will likely find the same info buried in
their FAQ pages somewhere.
So there.
|