virtual gives a virtual path to a document on the server.
<!--#include virtual="/includes/header.html" -->
To keep things organized, you can create a directory at the
root level called includes to house all of your
included files. The include parameter is telling the server
to include a 'virtual' file, one located in a directory
other than the one the document being parsed is in. The value
tells the server that the include is located in a directory
called 'includes', located at the root level. Using this method,
you can create all of your HTML pages with the same include, place
them in various directories and sub-directories, and the server
will be able to find your include; no error messages.
|
If you plan to use a single directory for all of your includes,
it would be a good idea to protect it from spiders and bots
with a
robots exclusion file,
especially if you give your includes an .html extension.
Leaving it wide open would result in the files in the directory
being indexed.
|
Now, if you plan to add a DOCTYPE <TITLE> and META tags
to your pages, and I suggest you do, you'll quickly find you've
got a different problem. If you include a single header file
on all of your pages they will all carry the same TITLE
and META tags. Not good. There's a way around that little
problem though; use two includes, one for the data above the TITLE,
and a second one for everything below the META tags.
Include #1, which I usually call header1 contains the doctype
and the opening html and head tags. No, you don't have to use
a special include for this, but what if you decide to convert
your 2000 page website from HTML 4.0 Transitional to HTML 4.0
Strict...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
Include # 2, which I call header2, contains the closing HEAD tag,
the BODY tag and everything else that you want in your header,
but not the main content of your page.
</HEAD>
<BODY bgcolor="#FFFFFF">
...all HTML, text, navigation or
images that make up the page header...
Your HTML document contains the include to header #1,
TITLE, the full path to
your style sheet, META tags, and the include to header #2. The
main page content comes below the include for header2. For those
copyright notices as well as bottom of the page navigation (or
anything else you want to include), you can add a footer include
after the main body content. So your entire web page template
would look something like this:
<!--#include virtual="/includes/header1.html" -->
<TITLE>Your Page Title</TITLE>
<LINK rel = STYLESHEET
href = "http://domain.com/styles/my.css"
Type = "text/css" >
<META NAME = "Description"
CONTENT = " Description of page">
<META NAME = "Keywords"
CONTENT = "keywords for page"
>
<!--#include virtual="/includes/header2.html" -->
....plug main page content in here...
<!--#include virtual="/includes/footer.html" -->
Header and footer includes can save hours and hours of labor
when it comes to site updates. But what if you'd like some
dynamic content in that header, say maybe a last modified
date. No problem. Save your includes with the HTML
extension and you can include an include in an include.
Huh?
file gives a pathname relative to the current directory.
../ cannot be used in this pathname, nor can absolute
paths be used.
<!--#include file="header.html" -->
With this method you would need a file called header.html
in each directory. That can be almost as hectic as having to
update individual pages whenever you make a change to your site.
On the other hand, if you're using the include file to update
say a news brief that appears only on one page, then this could
be rather handy as well. You might not want to allow someone
not versed in HTML to update the news section of your index
page, but would be very comfortable letting them update a separate
text file that will be included in the HTML document.