Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

Breadcrumbs for All

Rated 4.13 (Ratings: 6) (Add your rating)

Log in to add a comment
(19 comments so far)

Want more?

 
Picture of MartinB

Martin Burns

Member info | Full bio

User since: April 26, 1999

Last login: June 21, 2008

Articles written: 126

Several sites now have a breadcrumb trail as a navigation aid. The appeal is obvious: help the user work out where they are in a hierarchical site. It's pretty good usability, which is probably why Jakob Nielsen has one on his site. Here's how to add one to your own (Unix/Apache/Perl-hosted) site.

This code works for simple hierarchical sites - ones where there is a simple tree structure. Below the home page, there are a set of folders, each of which can have layers of subfolders. Each folder can contain pages. In other words, your basic site.

The reason for this is that this is not a re-creation of the user's browser history; it's a visualisation of a top-to-bottom path through your information architecture.

The way it works is extremely simple:

  1. Take a simple URL like
    http://foo.co.uk/articles/content/systems.html;
  2. Swap http://foo.co.uk for Home as it's the home page of the site;
  3. Swap systems.html for a sensible title (a truely gifted piece of code would pick this up from the page title with no performance loss. This is no such piece of code, sorry, it picks it up from a query string);
  4. Split the rest of the URL at the slashes;
  5. Add a link to all but the current page title;
  6. Stick the bits together in order, using a sensible separator such as ->;
  7. Output it all as a single string to the page.

This script does exactly that, with one other bit of cleverness - it capitalises the first letter of each bit, so that it appears more sensible to the non-technical than the lower case version which you'll probably be using in your URL schema.

There's also an additional extra which will only work if you're running on Perl5.004 or later. It will correctly capitalise non-English chars such as á, Þ, ö and ñ (the one unsupported exception appears to be ß). If this matters to you, and you are running Perl5.004 or later, then comment out the line:
use locale;

Also note:

You call the script by means of an SSI call:

<pre>&lt;!--#include virtual=&quot;/cgi-bin/cookie_trail.cgi?title=You%20put%20your%20title%20here&quot; --&gt;</pre>

and the (URL-encoded) query string sets the title;

The title can also have links in it as long as you escape all the HTML entities - useful if you want to have a sub-article without creating a subdirectory:

<pre>?title=&amp;lt;a href=&amp;quot;library.html&amp;quot;%20class=&amp;quot;crumb&amp;quot;&amp;gt;Building%20a%20library&amp;lt;/a&amp;gt;%20-&amp;gt;%20Current%20Reading%20List</pre>

My site has a special CSS class for the breadcrumb trail, so all the links output by the script will have class=&quot;crumb&quot; in them. If you want them out, then this is the line to edit:

<pre>$html .= qq|-&amp;gt; &lt;a href=&quot;$crumbs_path[$i]/&quot; class=&quot;crumb&quot;&gt;$crumbs[$i]&lt;/a&gt; |;</pre>

(you delete the class attribute and value).

Get the Code

Here it is

Martin Burns has been doing this stuff since Netscape 1.0 days. Starting with the communication ends that online media support, he moved back through design, HTML and server-side code. Then he got into running the whole show. These days he's working for these people as a Project Manager, and still thinks (nearly 6 years on) it's a hell of a lot better than working for a dot-com. In his Copious Free Time™, he helps out running a Cloth Nappies online store.

Amongst his favourite things is ZopeDrupal, which he uses to run his personal site. He's starting to (re)gain a sneaking regard for ECMAscript since the arrival of unobtrusive scripting.

He's been a member of evolt.org since the very early days, a board member, a president, a writer and even contributed a modest amount of template code for the current site. Above all, he likes evolt.org to do things because it knowingly chooses to do so, rather than randomly stumbling into them. He's also one of the boys and girls who beervolts in the UK, although the arrival of small children in his life have knocked the frequency for 6.

Most likely to ask: Why would a client pay you to do that?

Least likely to ask: Why isn't that navigation frame in Flash?

And for those of us using ASP...

Submitted by aardvark on December 28, 2000 - 15:05.

There's a tutorial on the site using an Active Server Pages solution. You can see it at Breadcrumbs for Those Using ASP.

login or register to post comments

And now for those of us using PHP...

Submitted by aardvark on December 31, 2000 - 11:24.

There's now a tutorial on the site using a PHP solution. You can see it at Breadcrumbs for PHP Lovers. Collect the whole set!

login or register to post comments

WTF do you put code in &lt;TEXTAREA&gt; tags?

Submitted by nictamer on January 3, 2001 - 10:16.

Why do you put code in <TEXTAREA>? Talk about useability! Textarea are for typing, not for reading. Plus you did'nt make it so it would NOT have an horizontal bar, therefore I only see couple dozen character wide at a time ... VERY frustratin to have a 21" monitor and only be able to see 30 characters at once ... I have a WAP phone if I want that kind of gymnastic, thank you.

login or register to post comments

Re: use of &lt;textarea&gt;

Submitted by aardvark on January 3, 2001 - 17:23.

I know this isn't pertinent to the article above, but to answer... We chose to use <textarea> blocks for code because it allowed for better rendering of the code within the page without creating giant scrolling pages. We wanted to keep the right-side navigation visible, and we also found some issues with <pre> blocks not rendering line breaks correctly. There were some other issues as well.

Ultimately we made sure that the <textarea> was HTML 4.01 Transitional compliant in its use, that it is not a barrier to accessibility, and that CSS controls its sizing (so if you enlarge your 4.x browser window, it should scale to fit the content area). To add the "wrap" attribute, which isn't widely supported and is often handled oddly by some versions of IE, would have broken that compliance. So we allow the browser and CSS to handle all display elements of the <textarea>.

So, I agree that it is a non-standard use of the <textarea>, and I even resisted it for a time. But ultimately, we know who our audience is and we've had very positive feedback on how its been implemented — people seem to prefer it over the use <pre> blocks.

login or register to post comments

Re: the use of &lt;textarea&gt;

Submitted by Jeff Howden on January 3, 2001 - 19:59.

There are certain penalties with using a <textarea>. However, there are definite disadvantages as well. If we were targetting IE4+ and NN6 only, then we could use a &lt;div&gt; tags with a set height and width overflow set to auto. If anybody has any better ideas of what we should use, feel free to drop me a line.

login or register to post comments

$PATH_INFO cleverness issue

Submitted by MartinB on January 8, 2001 - 11:26.

If you're using XSSI with this (and if you're on an Apache environment, you've probably at least thought about it), and you're splitting up your pages into snippets like this: /dir/index.html/1 (you're avoiding using query strings for the sake of search engines, and parsing the PATH_INFO instead), you'll run into problems. The above script will only dump the .html (or whatever) filename from the last part of the path - in the above example, it appears 1/2 way down. So replace the last section of code with this code.

login or register to post comments

aaarrgh

Submitted by Tijs on January 10, 2001 - 05:27.

Altough it may be a fine article it's absolutely unreadable in IE5/N4.7 on WIN98 since it's about 3 800px browser windows wide. For some reason reading 5 lines, scrolling to the right for 5 minutes, scrolling the textarea, going back, reading another 5 lines etc. is not purfect.

login or register to post comments

Debate

Submitted by blooze on January 10, 2001 - 07:08.

Any attempts to use to properly fit text to the screen width have failed utterly. I am using IE5 on a 21" monitor set to 1280x1024 resolution; with the browser maximized I only get about half (horizontally speaking) of the page on the screen.

login or register to post comments

Page width

Submitted by MartinB on January 15, 2001 - 04:29.

This is because the linebreaks in the comments aren't working properly, apologies. I've replaced the code sample with a link to it.

login or register to post comments

Problem executing the script.

Submitted by ckashrafi on February 15, 2001 - 04:43.

Hi, I am trying to implement this script on my website, and it returns a "[an error occurred while processing this directive]" error. My website uses SSI extensively without any errors, and is on a Unix/Apache/Perl server. In general, I would get this error if the includes page was incorrectly named or not on the server. The cgi file is in /cgi-bin/cookie_trail.cgi I checked and I believe I am calling the script correctly. Anyone have an idea on why this would be happening? Thanks, CKAshrafi

login or register to post comments

Problem diagnostics

Submitted by MartinB on February 15, 2001 - 07:31.

What do the error logs say?

login or register to post comments

Problem executing the script.

Submitted by ckashrafi on February 15, 2001 - 09:03.

You'll have to excuse me, the cgi realm is new to me. What error logs? If its the server error logs, how do I look at them on a shared server?

login or register to post comments

Error logs

Submitted by MartinB on February 15, 2001 - 09:43.

Ask your sysadmin for your error log (they should be able to produce one which is only your errors)

login or register to post comments

Problem executing the script.

Submitted by ckashrafi on February 15, 2001 - 18:00.

OK, I ran the cookie_trail.cgi w/ Perl in SSH terminal. The errors it gave me are as follows. Name "main::in" used only once: possible typo at cookie_trail.cgi line 74 (#1) (W) Typographical errors often show up as unique variable names. If you had a good reason for having a unique name, then just mention it again somehow to suppress the message. The use vars pragma is provided for just this purpose. Can't locate cgi-lib.pl in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 . /cgi-bin/) at cookie_trail.cgi line 61 (#2) Uncaught exception from user code: Can't locate cgi-lib.pl in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 . /cgi-bin/) at cookie_trail.cgi line 61. If I'm right, I can ignore the line-74 error. Besides the line-74 error, I believe that I'm missing a module. I found the cgi-lib.pl module at http://cgi-lib.berkeley.edu/. Could you please tell me which Version: 1.14 or 2.18 will work with your code, so I can ask the administrator of my website to install it. Sorry for the run-on message, don't know how to break lines. Thanks for your help. CKAshrafi

login or register to post comments

Off topic but...

Submitted by cymen on February 23, 2001 - 23:37.

Come on you guys. The textarea is great if you want to just copy and paste the code into another window (like an editor?)! Sure it sucks to have to scroll but you don't have to...

login or register to post comments

cgi-lib.pl

Submitted by MartinB on January 6, 2002 - 05:59.

Hi CKAshrafi

You don't need to get your sysadmin to install Perl libraries. Just stick it in the same directory as the main CGI and it should be fine. Either version will work, by the way, but the later version is probably wise.

login or register to post comments

IIS not executing virtual includes

Submitted by brants on March 16, 2002 - 20:29.

While I could certainly be playing with the .asp version, I'm trying to get the Perl version to work properly under IIS on Windows. I can get included scripts to be executed using "exec cgi=" but not using "include virtual=" -- rather in the latter case, IIS just returns the contents of the script as text. Any ideas on how I need to configure things differently? Thanks!

login or register to post comments

Minor point

Submitted by happysinger on March 25, 2002 - 19:01.

Just a small point of information... the author mentions that the capitalisation process does not support the German symbol ß. This is because this letter (the Scharfes S or S-Z) never appears at the start of a word, and as such has no capital version. Yours, Dave at happysinger.com

login or register to post comments

Breadcrumbs - cookie_trail.cgi

Submitted by mikemike on April 12, 2003 - 19:45.

Could someone post the code for the Perl cookie_trail.cgi.The link on this page is broken. Thanks

login or register to post comments

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

evolt.orgEvolt.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.