Common HTML Content

Question: I have my menu code on all HTML pages and it is rather long everytime I need to make changes since i have to update all the pages one by one and upload all of them to my server. Is there any way to do a single file that will control my menu on all pages, just like I do with CSS file? I have heard about PHP and SSI but I would really appreciate some guidance on these as I've never used it before.

Answer: To be able to use SSI or PHP requires that the particular option be installed on the web server. This means that you wont be able to test your pages fully before uploading them unless you also install a web server with the appropriate support on your own computer as well.

The first step would be to check which of these your hosting supports. If it supports both then PHP may be the better option as a complete programming language gives more flexibility for the future.

SSI requires that your pages have a .shtml extension in order to use them in the page unless you have the server configured to treat a different extension as equivalent (I set .htm as equivalent so that I can add SSI into all my existing pages). The following is how you include a file containing a section of your HTML using SSI.

<!--#include virtual="" -->

PHP requires a .php extension in order to use it (I have .html set to be treated as the equivalent).

<?php include="" ?>

The content of the included file is assumed to be HTML unless enclosed within a <?php ?> tag.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow