Skip to page content or Skip to Accesskey List.

Work

Main Page Content

Breadcrumbs For Those Using Asp

Rated 4.22 (Ratings: 6)

Want more?

  • More articles in Code
 
Picture of aardvark

Adrian Roselli

Member info

User since: 14 Dec 1998

Articles written: 85

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.

<% '############################

'##############################################################################

'# 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 " &gt; <a href=""" & DirPath & """ style=""text-decoration:none"">" & strTmpPath & "</a>"

END IF

Loop

IF PageTitle = "" THEN

response.write " : Current Page"

ELSE

response.write " : " & PageTitle

END IF

End Function %>

To call this code in your page, you need to call the include file and (if you want) set the variable 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">

<html lang="en-us">

<head>

<title><% = PageTitle %></title>

[...]

When you are ready to call the function on the page to display the breadcrumb trail, simply call it like this:

<% = 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.

A founder of evolt.org, Adrian Roselli (aardvark) is the Senior Usability Engineer at Algonquin Studios, located in Buffalo, New York.

Adrian has years of experience in graphic design, web design and multimedia design, as well as extensive experience in internet commerce and interface design and usability. He has been developing for the World Wide Web since its inception, and working the design field since 1993. Adrian is a founding member, board member, and writer to evolt.org. In addition, Adrian sits on the Digital Media Advisory Committee for a local SUNY college and a local private college, as well as the board for a local charter school.

You can see his brand-spanking-new blog at http://blog.adrianroselli.com/ as well as his new web site to promote his writing and speaking at AdrianRoselli.com

Adrian authored the usability case study for evolt.org in Usability: The Site Speaks for Itself, published by glasshaus. He has written three chapters for the book Professional Web Graphics for Non Designers, also published by glasshaus. Adrian also managed to get a couple chapters written (and published) for The Web Professional's Handbook before glasshaus went under. They were really quite good. You should have bought more of the books.

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.org Evolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.