Skip Navigation Links.
Using Include files to Give Your Site a Consistent Look and Feel
Language(s):ASP
Category(s):Include Files

This example shows how to place the common code for your Header and Footer sections in a single file, which is then included in all other ASP files.

<!--
Using Include files to Give Your Site a Consistent Look and Feel

Jon Vote, Idioma Software Inc. 

03/2002 

www.idioma-software.com 

A very powerful feature of ASP is the ability to use Include files containing common routines that are shared among many other pages. A good use of Include files is in maintaining a consistent look and feel for your sites. Web pages are generally a Header followed by Content followed by a Footer. It is a simple matter to write a common Header routine and a common Footer routine that is called from all other ASP pages on your site. The code for the Header and Footer reside in one and only one place. If you decide to change the look and feel, you can do so by changing only the Header and/or Footer routines. You can even have a page that changes based on the time of day or month (not shown here). 

The example below uses a common Header and Footer routine to give a consistent look and feel to three example ASP pages. The Header and Footer code is contained in HeaderFooter.inc along with a couple of string parsing routines used to return the name of the currently running ASP page. The Header routine makes use of this information to include or not include a link for the calling page at the left margin menu. 

To install this code on your machine, please follow the instructions below. You will be creating 4 seperate files so be sure to cut and paste in the appropriate spots. 

1) Create HeaderFooter.inc by copying and pasting the code between the areas marked below. 
2) Create Page1.asp by copying the code indictated for Page1.asp below. 
3) Create Page1.asp by copying the code indictated for Page2.asp below. 
4) Create Page1.asp by copying the code indictated for Page3.asp below. 
5) You should now have 4 files. Three .asp pages and an include file that is called by each. Open either Page1.asp, Page2.asp or Page3.asp. 
--> 




<!-- Begin code for HeaderFooter.inc --> 

<% 'PutHeader - Put the standard header 
Public Sub PutHeader(ByVal strCaller) 
%>

 <BODY BGCOLOR="005050" TEXT="#FF0066" ALINK="#FF0000" VLINK="#FF00FF" LINK="#00FFFF">

 <CENTER>
    <H3>Using Include Files to Give Your Site a Consistent Look and Feel</H3><BR>
 </CENTER>
 <Table>
  <TR>
   <TD BGColor="0000FF"> 
    <UL>
 <%
  Response.Write "<LI>"
  If strCaller = "Page1.asp" Then 
    Response.Write "Page1"
  Else
    Response.Write "<A Href=Page1.asp>Page1</A>"
  End If  
  Response.Write "<LI>"
  If strCaller = "Page2.asp" Then 
    Response.Write "Page2"
  Else
    Response.Write "<A Href=Page2.asp>Page2</A>"
  End If  
  Response.Write "<LI>"
  If strCaller = "Page3.asp" Then 
    Response.Write "Page3"
  Else
    Response.Write "<A Href=Page3.asp>Page3</A>"
  End If  
 %> 
    </UL> 
<TD Width="90%">
<%
End Sub
%>

<% 'PutFooter - Put the standard footer
Public Sub PutFooter()
%>
 </TR>
 </TABLE> 

 <CENTER>
  <H4>This Sample Code Brought to You by
   <a href="http://www.idioma-software.com">
    Idioma Software Inc.
   </A>
   <BR>Quality Software Solutions 
  </H4>
 </CENTER>

<%
End Sub
%> 

<% 'GetCallerName - Returns the file name of the calling routine.
Public Function GetCallerName() 
 GetCallerName = JustTheFile(Request.ServerVariables("SCRIPT_NAME"))
End Function
%> 

<% 'JustTheFile - Strips the Path name, returns only the file name.  
'
'For similar path parsing routines see: 
'
'    Useful Routines for Parsing Path Names
'    www.skycoder.com 

 Public Function JustTheFile(ByVal strPathName) 
   
  Dim intPos
  
  intPos = InStrRev(strPathName, "\")
  If intPos = 0 then 
    IntPos = InStrRev(strPathName, "/")
  End If 
  If intPos = 0 then 
    IntPos = InStrRev(strPathName, ":")
  End If 
  
  If intPos > 0 then 
    JustTheFile = Mid(strPathName, intPos+1)
  Else 
    JustTheFile = strPathName
  End If 

 End Function 
%>

<!-- End code for HeaderFooter.inc -->




<!-- Begin code for Page1.asp --> 

<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %> 
<!--#Include File=HeaderFooter.inc --> 

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>

<% Call PutHeader(GetCallerName()) %>
 
    Are you still copying all of your header and footer text 
    from HTML page to HTML page?? Well, no more. Now with the 
help of Include files and for a nominal fee of zero 
dollars and zero cents YOU TOO can have it all. 
Simply create a separate file, which will be 
included in all your asp pages. In this routine, you 
define a procedure called PutHeader that will send the 
HTML for the top part of your page. Write another routine 
called PutFooter that will send the HTML for the bottom part 
of your page. Now you declare the include file at the top 
of each page and call the PutHeader routine at the top and 
the PutFooter routine at the bottom and Whoa Dude! You 
have consistency!

<% Call PutFooter %>

</BODY>
</HTML>

<!-- End code for Page1.asp -->




<!-- Begin code for Page2.asp --> 

<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %> 
<!--#Include File=HeaderFooter.inc --> 

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>

<% Call PutHeader(GetCallerName()) %>
<CENTER>
<TABLE> 
 <TH ColSpan=3>Here is a table just sort of for laughs.</TH>
 <TR> 
  <TD>A<TD>B<TD>C
 </TR>
 <TR> 
  <TD>D<TD>E<TD>F
 </TR>
 <TR> 
  <TD>G<TD>H<TD>I
 </TR>
 <TR> 
  <TD>J<TD>K<TD>L
 </TR>
 <TR> 
  <TD>M<TD>N<TD>O
 </TR>
 <TR> 
  <TD>P<TD>Q<TD>R
 </TR>
 <TR> 
  <TD>S<TD>T<TD>U
 </TR>
 <TR> 
  <TD>V<TD>W<TD>X
 </TR>
 <TR> 
  <TD>Y<TD>Z<TD>:)
 </TR>
</TABLE>
</CENTER>
<% Call PutFooter %>

</BODY>
</HTML>

<!-- End code for Page2.asp -->




<!-- Begin code for Page3.asp --> 

<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %> 
<!--#Include File=HeaderFooter.inc --> 

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>

<% 
 Dim i 
 Call PutHeader(GetCallerName())
 For i = 1 to 10 
   Response.Write "I'm not sure what to put here so I'll just leave it blank<BR>"
 Next  
 Call PutFooter 
%>

</BODY>
</HTML>

<!-- End code for Page3.asp -->


This article has been viewed 5409 times.
The examples on this page are presented "as is". They may be used in code as long as credit is given to the original author. Contents of this page may not be reproduced or published in any other manner what so ever without written permission from Idioma Software Inc.