Main Page Content
Breadcrumbs For Those Using Asp
Instead of going through the usefulness of the breadcrumb navigation concept all over again, I'll just refer you to Martin's article, Breadcrumbs for All. It's a great tutorial for those of us with Perl and Unix/Apache servers, but it leaves out those of us using ASP on IIS. It also leaves out a few others, but I'm just doing ASP here, so cut me some slack.You can see a sample of this code in action at the Kenan Center site (the Recreation section has the most depth right now). This site has only a few levels of directories, but it is still just as useful on that site as on extremely deep sites.One thing to keep in mind is that you have to name directories in plain english (or your human-readable language of choice) since it uses the directory names for the breadcrumb. This function will capitalize the words in the directory names, and it replaces all underscores with spaces for display. It does not handle special characters, but then again, neither does the Windows file system (at least not extended characters). It's a simple matter of using a
replace()
function against a pre-defined list of characters to enable that, however.The code should be created as an include file called breadcrumb.asp
and stuffed into your general includes directory. The page that calls it should have a variable called PageTitle
that is the name of the page. This variable is used by breadcrumb.asp
(and if you're smart, the file calling it) to list the current page. If the variable is blank, however, it just uses the words "Current Page." It's also worth noting that this script goes right to the root of the site with its links, which may or may not be what you want.<% '############################To call this code in your page, you need to call the include file and (if you want) set the variable'##############################################################################
'# breadcrumb.asp Version 1.0 #'# Copyright 2000 Adrian Roselli adrian@roselli.org #'# Created 24/4/2000 Last Modified 24/4/2000 #'##############################################################################'# COPYRIGHT NOTICE #'# Copyright [and -left] 2000 Adrian Roselli All Rights Reserved except as #'# provided below. #'# #'# breadcrumb.asp may be used and modified free of charge by anyone so long #'# as this copyright notice and the comments above remain intact. By using #'# this code you agree to indemnify Adrian Roselli from any liability that #'# might arise from it's use. #'# #'# This script is released under the GPL. #'# Selling the code for this program or any derivative work is expressly #'# forbidden. A full copy of the GPL can be found in the Code section of #'# http://evolt.org. In all cases copyright and this header must remain #'# intact. #'##############################################################################Function BreadCrumb(FullPath)Do Until instr(1,FullPath,"/") = 0
'## Create an array of letters in the alphabet.
Letters = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")'## split on the /
tmpPath = mid(FullPath,1,instr(1,FullPath,"/")-1) strTmpPath = Trim(tmpPath) DirPath = DirPath & strTmpPath & "/"'## upshift the first character
firstLetter = ucase(mid(strTmpPath,1,1)) strTmpPath = firstLetter & mid(strTmpPath,2,len(strTmpPath))'## replace udnerscores with spaces and upshift the following character
for each letter in letters strTmpPath = Replace(Trim(strTmpPath),"_" & lcase(letter)," " & UCase(letter)) next'## split the next one out
FullPath = mid(FullPath,instr(1,FullPath,"/")+1,Len(FullPath)-Len(tmpPath))'## separate them with >> symbols
IF strTmpPath = "" THEN response.write "<a href=""/"" style=""text-decoration:none"">Home Page</a>" ELSEIF strTmpPath = "Home" THEN ELSE response.write " > <a href=""" & DirPath & """ style=""text-decoration:none"">" & strTmpPath & "</a>" END IFLoopIF PageTitle = "" THEN
response.write " : Current Page"ELSE response.write " : " & PageTitleEND IFEnd Function %>
PageTitle
as something. For example:<% PageTitle = "About Us" %><!--#include virtual ="/includes/breadcrumb.asp"--><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">When you are ready to call the function on the page to display the breadcrumb trail, simply call it like this:<html lang="en-us">
<head><title><% = PageTitle %></title>
[...]
<% = BreadCrumb(Request.ServerVariables("PATH_INFO")) %>The code can easily be tweaked, and some things changed or modified (like the
Letters
array, or setting the PATH_INFO
server variable as a variable early in the script) depending on your needs. You can modify the HTML that displays the breadcrumb in the include file so it matches your site styles as well.