SSI:Include

The menu running down the left hand side of this page and the colophon used to indicate the end of page text are features that are shared by every other page on this site. Having to write the HTML code necessary to deliver these features repeatedly would be both tedious and prone to error. Thankfully, this is not necessary. Instead, we simply use an SSI include directive. For instance the directive

<!--#include virtual="/includes/colophon.html" --> incorporates the HTML code

<div style="text-align:center;padding-top:5px">
<img src="/images/exd.png" alt="Colophon" height=14 width=56/>
</div>

which results in the colophon being displayed at the bottom of each page on this site. The path to the file contents to be merged can be specified in one of two ways

The file contents thus merged do not have to be static. One can just as easily run a CGI script and merge its results. For instance <!--#include virtual="/scripts/myip.php" --> causes the text Your IP address is 38.107.191.83 to be merged into this paragraph.

On the odd occasion it is necessary to nest SSI directives.. In other words, the file contents being merged using a #include directive could in turn contain other SSI directives. How does one ensure that the webserver will process such nested directives? The answer turns out to be surprisingly easy - simply use the extension .SHTML for the original included file. As soon as it is accessed for inclusion, its .SHTML inclusion will trigger parsing of any SSI directives in its contents. Although perfectly legal, there should never be any reason to have more than one level of SSI nesting. A final point to note - always double check to make sure that nested SSI directives don't end up creating a loop!

Jump To...

Colophon