Quick Coldfusion Breadcrumbs

Sometimes you may find the need to output a trail of breadcrumbs which simply reflect the directory structure of where you are in the site, including the current template (.cfm file).

By looping over the cgi.script_name variable, we can cut up the various paths into individual entries which we can then output.
NB, remember to escape those URL variables.

  //Start a new query which we can fill 
   qBreadcrumbs=QueryNew("url,title", "varchar,varchar"); 
   //The starting link 

<cfloop list="#cgi.SCRIPT_NAME#" delimiters="/" index="i"> 
       // Add a row to our query 
       QueryAddRow(qBreadcrumbs, 1); 
       // Set the row with URL 
       QuerySetCell(qBreadcrumbs, "url", link & i); 
       // Set the row with the title: If '.cfm' exists, remove it, and replace underscores with spaces 
       // You could also use the TitleCase() function (see http://lab.artlung.com/coldfusion-titlecase/ ) to auto capitalise 
       QuerySetCell(qBreadcrumbs, "title", "#replace(replace(i, '_', ' ', 'all'), '.cfm', '', 'all')#"); 
       //Update the link location for the next loop 
       link=link & i & '/'; 

<div id="breadcrumbs"><cfif qBreadcrumbs.recordcount GT 1><p><a href="/" title="Home">Home</a> 
    <cfloop query="qBreadcrumbs"> 
            <cfif title NEQ "index">&nbsp;&raquo;&nbsp;<a href="#url#" title="#title#">#title#</a></cfif>