Server side includes tutorial: Include tag

To illustrate this example, let's suppose we have a file with the content bellow:
 

head.txt
<html>
<title>Submitside.com: SSI tutorial</title>
<body bgcolor=FFFFFF>
<center>
<h1>Submitside.com: SSI tutorial</h1>

This file may content the first part of all pages in our site. Now we may want to add the content of this page to a file name "lesson1.shtml":



 
Option 1
 
lesson1.shtml
<!--#include file="head.txt" -->

This is the content of lesson 1.<br>
And this is the end.
</center>
</body>
</html>

In this case, by using the code above, we will be able to include file name "head.txt" in the first part of file "lesson1.shtml". This procedure may be repeated with files "lesson2.shtml", "lesson3.shtml", etc.

The code above will allow to include a file named "head.txt" and located in the same directory as "lesson1.shtml" in the first part of the file. In this case, the included file must be in the same directory

Option 2
 

lesson1.shtml
<!--#include virtual="/ssi/head.txt" -->

This is the content of lesson 1.<br>
And this is the end.
</center>
</body>
</html>

In this case we are providing the virtual path within our main directory, so that we are not limited by the location of the file to be included in our pages.



The file to be included must be a text file, and its name may have ".html", ".txt", ".asp" ... extensions. In case ".asp" extension is used (in Windows NT servers), you may be able to execute ASP scripts with no problems (probably your file must have ".asp" extension ).


Tutorial home page

2010@ Submitside.com. All rights reserved.