Place your message here

Your Guide to Professional
Web Site Design and Development

Web Development
HTML Codes
HTML Tips
Javascript Snippets
216 Safe Colors
Symbols
Web Directory
Web Resources
Internet Channels

Web Development: Business, Advertising, Internet Marketing, Promotion and Web Site Design

| Web Development | HTML Codes | HTML Tips | Javascript Snippets | 216 Safe Colors | Symbols | Recommendations |

Server Side Includes: Navigation Links

By William Bontrager

Server Side Includes (SSI) technology can be used to include the same content on many pages. But when it is used for including the same navigation menus on every page, there is one big drawback -- the menu item for the current page links to the current page.

While there is nothing intrinsically wrong with that, if you prefer to have the menu item for the current page be unlinked (or the menu item omitted altogether) then this article will show you one way to do that.

A set of demonstration pages, along with a link to download them, is at http://willmaster.com/a/20t/pl.pl?demo203

This article assumes you have read the "Server Side Includes" article or have a working knowledge of the basics of including content in web pages using SSI.

The pages that include the navigation menu have the same tags they would have for including any text with SSI, something like this:

<!--#include virtual="menu.shtml"-->

Instead of being static text, the file being included will also be parsed as an SSI file. Thus, the name of the file being included must end in .shtml (or other extension your hosting company has specified for SSI.)

The balance of this article is about the content and SSI tags of the file being included, the file that contains the navigation menu and links.

The SSI tags in the included file, which I'll talk about presently, mean:

     If the menu item is for the current page, print one
     thing. Otherwise, print something else.

It takes three different SSI tags to accomplish that. We'll call them the #if tag, the #else tag, and the #endif tag. The three tags can be considered to be a set. A set is required for each navigation menu item.

For example, let's suppose the "Home" menu item refers to the index.shtml page. When index.shtml is being sent to the browser, we print [Home] without a link (or print nothing, if you prefer). However, if some other page is sent to the browser, we would make the [Home] menu item into a link.

The #if part of the SSI tag set checks to see whether or the site visitor is currently viewing index.shtml. If s/he is, then [Home] without a link is printed. Otherwise, the #else tag kicks in and causes [Home] to be linked and printed. The #endif tag marks the end of the set.

The #if part of the SSI tag set is the one that requires the most explanation.

In the example below, you'll see a variable named $DOCUMENT_URI (yes, "URI" instead of "URL").

The $DOCUMENT_URI is the URL of the current web page but with everything up to and including the domain name removed. If the current page happens to be http://domain.com/index.shtml then the URI is /index.shtml. Or, if the current page happens to be http://domain.com/books/sales.shtml then the URI is /books/sales.shtml

The $DOCUMENT_URI variable contains the URI of the page currently being viewed. That URI is compared with the URI of the web page the menu item refers to.

Instead of explaining the whole process with narrative, here is an example:

<!--#if expr="\"$DOCUMENT_URI\" = \"/index.shtml\"" -->
[Home]
<!--#else -->
<a href="index.shtml">[Home]</a>
<!--#endif -->

The value of $DOCUMENT_URI is compared to /index.shtml. They are equal to each other only if the page currently being viewed is index.shtml.

     ~ If (the #if tag) the value of $DOCUMENT_URI is
       /index.shtml, [Home] without the link is printed.
~ Otherwise (the #else tag), [Home] with the link is printed. ~ The #endif tag marks the end of the set.

The content line below the #if tag and the content line below the #else tag may be multiple-lines. You're not restricted to just one line of content.

Use one set of if-then-else SSI tags for each menu item of your navigation area. Change the URI and link URL of each set to reflect the page the set's menu item refers to.

Note that the expression in the first line of the set, the #if SSI tag line, is enclosed within quotation marks. Therefore, any quotation marks within that expression must be escaped with a backslash. Both the $DOCUMENT_URI variable and the actual URI on the #if SSI tag line are enclosed within backslashed quotation marks.

That's actually all there's to it.

Simply make a file with one set of if-else-endif SSI tags for each navigation menu item. Then include that file in your web pages.

Will Bontrager

About the Author:

Copyright 2003 Bontrager Connection, LLC
William Bontrager Programmer/Publisher, "WillMaster Possibilities" ezine mailto:possibilities@willmaster.com

Are you looking for top quality scripts? Visit Willmaster and check out his highly acclaimed Master Series scripts. Some free, some for a fee.

Back