ASP Breadcrumbs
The code below allows you to generate a site breadcrumb from a path. So if a template is invoked in this directory:
/news/breaking/from_the_front
This procedure will generate a breadcrumb that looks like this:
News > Breaking > From the Front
Each element of the breadcrumb will link to an index file in the directory represented. This code capitalizes each element of the breadcrumb, but excludes words like "an", "the", etc. from capitalization. It doesn't currently grant an exception to that rule when those words come first in the breadcrumb element, but that should be pretty easy to fix. This code is provided "as is". Use at your own risk.
<%
' Procedure Name: show_breadcrumb
' Author: Jim Biancolo
' Date Created: 11/6/2001
'
' Notes
' *****
' Displays the breadcrumb based on a path and a title.
'
' Parameters
' **********
' path
' path to parse into breadcrumb
' title
' page title to display at the end of the breadcrumb. Couldn't use
' the filename in my case, but this code could easily be adapted to
' that purpose.
'
' Revision History
' ****************
' Change date:
' Change by:
' Change notes:
Sub show_breadcrumb (path, title)
'--- Variable declarations ---
dim breadcrumb
dim separator
dim curr_link
dim d_no_caps
dim path_elem
dim word
'--- Initialization ---
curr_link = "/"
separator = " > "
'--- Set dictionary of words that shouldn't be capitalized ---
Set d_no_caps = CreateObject("Scripting.Dictionary")
d_no_caps.Add "a", "1"
d_no_caps.Add "an", "1"
d_no_caps.Add "and", "1"
d_no_caps.Add "the", "1"
'--- Trim leading "/" from path ---
If StrComp(Left(path, 1), "/") = 0 Then
path = Right(path, Len(path) - 1)
End If
'--- Build breadcrumb w/ links ---
Do While InStr(path, "/")
'--- Insert breadcrumb element separator ---
If Len(Trim(breadcrumb)) > 0 Then
breadcrumb = breadcrumb & separator
End If
'--- Start link for breadcrumb element ---
curr_link = curr_link & Left(path, InStr(path, "/") - 1) & "/"
breadcrumb = breadcrumb & "<a href=""" & curr_link & """>"
'--- Parse each word in the path element, decide to capitalize ---
path_elem = Left(path, InStr(path, "/") - 1) & "_"
Do While InStr(path_elem, "_")
word = Left(path_elem, InStr(path_elem, "_") - 1)
If Len(Trim(word)) Then
If d_no_caps.Exists(word) Then
breadcrumb = breadcrumb & " " & word
Else
breadcrumb = breadcrumb & " " & UCase(Left(word, 1)) & LCase(Right(word, Len(word) - 1))
End If
End If
path_elem = Right(path_elem, Len(path_elem) - InStr(path_elem, "_"))
Loop
'--- Remove parsed portion of path (eventually terminating WHILE loop) ---
path = Right(path, Len(path) - InStr(path, "/"))
'--- End link in breadcrumb element ---
breadcrumb = breadcrumb & "</a>"
Loop
breadcrumb = breadcrumb & separator & title
Response.Write(breadcrumb)
End Sub
%>







