Include files is a great feature and will hopefully become a great resource
to yourself. I use include files in all of my application as well as my website.
Instead of re-entering the same code over and over again you can create one file
and include it on other pages. Such as a page header and footer. You will notice
on AaronOutpost.com there is the same header and footer on every page. I used an
include file to load header.asp and footer.asp which are in my virtual
directory. So how can you do it?
Include file command only works on .ASP files but it is actually entered
outside the script tags <% %>.
|
<!-- This script will fail
-->
<%
If view <> "print" Then
<!-- #include
file="header.asp" -->
End If
%> |
|
<!-- This script will work -->
<%
If view <> "print" Then %>
<!-- #include
file="header.asp" -->
<% End If %>
|
The virtual and file
keywords indicate the type of path you are using to include the file, and
filename is the path and file name of the
file you want to include.
Included files do not require a special file name extension;
however, it is considered good programming practice to give included files an
.inc extension to distinguish them from other types of files. I however do not
do this because it makes for easier editing if all files have the same extension
.asp. I name my include files inc_filename.asp
Using the Virtual Keyword
This uses
the virtual directory as a base. I use this for the include files that you see
on the left and right side of AaronOutpost.com. Since you will be browsing
multiple directories on the website, I needed to have the files link to it's
physical place on the server. Let's say you have a my calendar on your website.
It would reside in Calendar. You want to include the mini calendar on all of the
pages so you would use the following.
<!-- #include virtual ="Calendar/inc_mini_calendar.asp" -->
Using the File Keyword
Now lets
say you want to use the relative directory. Maybe you want the header to change
depending on what directory you are in.
<!-- #include file ="header.asp" -->
Now you
can still call files from sub directories using the file command.
<!-- #include file ="includes/header.asp" -->
So create a header.asp and a footer.asp that contains an html layout for your website. Your include files can also contain ASP script.
In the final example I include AaronOutpost.com Header and Footer files.