g
Printer Friendly Version

editor  
BellaOnline's HTML Editor
 

SSI - Server Side Include - II

In the first part of this tutorial we discussed using server side includes to streamline your HTML code. You also learned that the decision to use the file argument or the virtual argument depends on the location of the files on the server. Now we will take a closer look at the file and virtual arguments.

Let's study some examples. For the purpose of these examples, we have two files called index.shtml and about.shtml. These two files contain the SSI code that will "call in" a third file.


Figure 1 File Argument


Figure 2 Virtual Argument


Example 1
<!--#include file="menu.html"-->

As you can see from Figure 1 above, all three of the files (index.shtml, about.shtml and menu.html) are in the same folder on your server. Therefore in this example you will use the file argument in the SSI code. Also the value (on the other side of the equal sign) is simply the name of the file to be included (menu.html). By using the file argument and the name of the file you are telling the server that it can find the file it needs (menu.html) in the same folder as the index.shtml and about.shtml files.

Example 2
<!--#include file="law/legal.html"-->

In this example we still have the SSI code in both the index.shtml and about.shtml webpages. Take a look at Figure 1 again. This time the file we want to include (legal.html) is in a folder below the main folder. This subfolder is called law. Because the legal.html file is in a subfolder you need to add the name of the subfolder in front of the name of the file to be included. Because the law folder is a subfolder of the main folder you will still use the file argument. This tells the server that it can find the file it needs (legal.html) in the law subfolder.

Example 3
<!--#include virtual="/commons/refer.html"-->

Take a look at Figure 2. In this example we still have the SSI code in both the index.shtml and the about.shtml webpages. But this time we will use the virtual argument. Why? Well this time the file to be included (refer.html) is not in the same folder or a subfolder to the main folder. It is in an independent folder on the server. That is to say this folder is "outside" of the main folder. How do you tell the server to look outside of the main folder? You need to add the / in front of the name of the folder. The / stands for the server root or domain name of your webpage (www.yoursite.com). By using this / and the virtual argument, you are telling the server that it can find the file it needs (refer.html) at the location www.yoursite.com/commons/refer.html.




This site needs an editor - click to learn more!

HTML Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Editor Wanted for details.



| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor