Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Includes

May 8, 2000

include

An include inserts the text (or images) of another document into the parsed document. If you learn nothing else about SSI, learn includes. If you've been creating web pages for very long you've already run into the problem of having to change multiple pages every time you change your site design, your header/footers, or your navigation. Not a fun job. Or, you could inherit a web-site with 2000+ pages like I did... all hardcoded. Come time to change that copyright date and you've got a big problem. This is where includes come in so handy. Change just one file, the include, and your entire site is instantly updated!

The include has two parameters, use the wrong one to update a site with multiple directories and you'll have multiple error messages instead of instant update.

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.

The config directive
Server Side Includes
Printing Environment Variables with echo


Up to => Home / Authoring / SSI / Intro




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers