How to Create Server Side Includes Print

  • 0

 

Server Side Includes (SSI) give you the ability to reuse HTML code by creating a separate file that can be referenced on any page within your site using a special directive (see below). When called in a browser, the code in the SSI file is executed at the same time as main page's HTML. As a result, the page pulls up both sets of code and they are run at the same time.  This article pertains to Windows Hosting Plans on IIS only.

You can use the same SSI file on any page on your site. In fact, you can even nest SSI's by including other SSI's on your included page. There are special directives that are beyond the scope of this document that can be used as well. e.g. Including the Date and Time. Seehttp://www.georgedillon.com/web/ssi.shtml

 

To Activate SSI's on your Site:

  1. Name your base HTML files with the traditional .shtm or .shtml extensions so the web server will know that you intend to use SSI reference on that page. Then include your SSI (Server Side Include) code below.
  2. Submit a ticket with your domain name and we can make normal .html and/or extensions so you can use add a SSI. That's what we do.

 

To include a SSI on a web page:

  1. Make a file with the code to be included and name it with a .inc, .txt, .shtml or even .html extension. You can do this in notepad or another text editor. Place it in your website's WWWROOT folder or other sub-directory.
  2. Use the code below on your primary page to reference your included file. You can include multiple SSI's on one page and you can reference the same file on other pages.
  3. Insert Code to call the SSI(s)
  4. There are two ways of inserting SSI's into your page. Note, these are just example pages and directories.
    <!--#include file="index-menu.inc"--> OR <!--#include virtual="/inc/index-menu.inc"-->

 

The first way will reference the file relative to the directory the base file is in. The second way references the file relative to the website's root directory (WWWROOT)-- due to the beginning forward slash and the use of the "virtual" attribute. The second method is sometimes better because it ensures your SSI will work on all pages regardless of the sub directory. Note: in both cases you cannot use the full "http://www.domain.com/inc/index-menu.inc" URL. It must be a relative URL.

 

See the following site for more information with some fine examples and an SSI tutorial: http://www.georgedillon.com/web/ssi.shtml

 

* Please note when researching SSI information note there are some differences between available directives on Windows IIS, Windows with Apache and Linux. We use Windows with IIS.

 

 


Was this answer helpful?

« Back