Web Communications

You are here

Server-Side Includes

What is a Server-Side Include?

A server-side include is a line of code placed in a webpage that instructs the web server to insert the contents of a specified file (often referred to as an include file) into your webpage before displaying it. The main advantage of using a server-side include is that you can save information, such as a banner, menu, or footer, in a single file. When you need to update that information, you edit the include file, and any webpages that reference the include file will immediately reflect the updated information.

Typical Uses for Server-Side Includes

One of the most common uses for server-side includes is to create header, navigation, and footer files for a website. The include file can contain such elements as text, JavaScript, graphics, and links.

Headers:

Headers typically contain the following types of information:

  • A standard banner or logo
  • Department name
  • Search bar

Navigation:

Navigation menus contain the top-level links for navigating your website and should appear on every page.

Footers:

Footers typically contain a copyright notice and similar types of information. For example:

  • Copyright date
  • Department name
  • Contact email address
  • Date of last modification
  • Link back to the department's main homepage or a link back to the UNLV homepage

How to Create a Footer

Here's an example of a typical UNLV footer:

© 2006 University of Nevada, Las Vegas. Send comments to UNLV Web Communications. Last updated Friday, 17-Mar-2006 14:50:05 PDT.

Here's how we did it:

Step 1:

First, we created a new file and typed the following text in the file.


<p>&copy; 2006 University of Nevada, Las Vegas. Send comments to UNLV Web Communications. Last updated <!--#echo var="LAST_MODIFIED" -->.</p>

Step 2:

Next, we saved the file as footer.html. NOTE: The file does not contain any other text or HTML tags. To include the date of last modification, place the following line of code in your include file:


<!--#echo var="LAST_MODIFIED" -->

This code resets the date every time you modify your webpage. Be sure to name your include file with a .html extension.

Step 3:

Now that you've created your include file, you need to insert code into your webpage telling it to get the contents of the include file. Be sure to place the code in your file exactly where you want the footer to appear on your webpage. Here's an example of what the server-side include should look like:


<!--#include virtual="footer.html" -->

TIP: Replace the word footer.html with the name of your include file. Also, make sure your code points to the correct location of your include file. In this example, we assumed that the include file was in the same directory as the webpage. If you place your include file in a separate directory, be sure to include the directory path. The following example references an include file that has been saved in a subdirectory named include:


<!--#include virtual="include/footer.html" -->