First time here? You may want to check out the blog archive, subscribe to the RSS feed, sign up for free email updates, or follow me on Twitter. Thanks for visiting!

Fixing the DNN Breadcrumb Skin Object 

We've all seen them; the bar of links usually found at the top of websites with multi-level navigation. Location breadcrumbs aide visitors in traversing content-rich sites by providing feedback on how "deep" visitors have navigated into the site and on how to get back where they came from. If properly implemented as text links, breadcrumbs also provide SEO benefits by allowing search engine spiders to more effortlessly crawl web content.

The DNN breadcrumb skin object, which is installed by default, makes it easy to implement breadcrumbs in your skins so there is really no excuse not to use them. Placing this line <dnn:Breadcrumb runat="server" id="dnnBreadcrumb" RootLevel="0" /> into your ascx-based skin renders the path to the currently selected tab in the form of TabName1 > TabName2 > TabName3. Optionally, you may specify a breadcrumb separator and a CSS class.

The only rub that I have with DNN's breadcrumb skin object is that the last item in the trail also renders as a link. You may think "what's the big deal," but I like to argue that this shortcoming works against the very benefits discussed above. Why would I want to navigate to the page that I'm already on?

So what's a dedicated DNNer to do? Here are 3 approaches one might take to "fix" the DNN breadcrumb skin object:

  1. Hack the breadcrumb trail with JavaScript.
  2. Modify the DNN skin object code.
  3. Write a custom breadcrumb skin object.

Let's look at these approaches one at a time.

JavaScript Hack

We simply target the last item in the breadcrumb trail and remove the href attribute. We then adjust the style due to the fact that even without a href attribute the <a> tag remains, which means it takes on the default link style although it's not a "live" link. Download the script here. Not the most elegant solution, but it works.

Modify the DNN Skin Object Code

This time around we add an additional public property - LastAsSpan - to the Public Members region of breadcrumb.ascx.vb that allows us to enable or disable the rendering of the last item in the breadcrumb trail as a link. Still in breadcrumb.ascx.vb, we then turn our attention to the Page_Load event handler and add a few lines of code that ultimately process our new setting. Download the commented code and then backup and replace breadcrumb.ascx.vb in admin/skins. No recompiling necessary, but you may have to restart DNN to clear the cache. For the politically correct, this constitutes a DNN core change and therefore gets overwritten by subsequent DNN upgrades. So again, far from ideal and more an illustration of concepts then a real-world solution.

Write a Custom Skin Object

This approach makes the most sense on all fronts and follows the "official" guidelines on extending DotNetNuke. Just install the custom skin object, register the new control and change the breadcrumb declaration in your existing skins and you are done. More details in the free download. I'm only a DNN module developer during REM though, so for anyone interested in the nitty-gritty of writing your own skin objects, keep an eye on Mitchel Sellers' blog later this week.

So there you have it, 3 roads to breadcrumb heaven. I'll leave it up to you to decide what approach works best for your unique situation.

In closing, I would like to thank Vasilis Terzopoulos and Mitchel Sellers for their generous contributions to this post. As always, post your comments and questions below. And if you have enjoyed this material, consider subscribing to our RSS feeds or signing up to get blog updates by email.

 




Comments

Sam MacDonald Sam MacDonald says:

Great article on how to accomplish this. I like the direction you took of writing about three options to accomplish the task. Instead of just taking and specifying one way of doing it.

Tom Kraak Tom Kraak says:

Thanks for picking up the post on your blog ... much appreciated!

Vitaly Kozadayev Vitaly Kozadayev says:

Great post. Quick note, though - in the email, all links are broken because HREFs are relative paths...

Also, can you give me some guidance/pointers on ASPDOTNETSTORE module? I just got it and wanted to learn from you, as you said elsewhere that you use it often?

Tom Kraak Tom Kraak says:

Sorry about the broken links in the email, I totally forgot.

ASPDNSF was generous enough to send me an eval copy for review, but I just haven't gotten around to it yet.

Do you have specific questions? Have you installed it yet?

erik erik says:

I like having the last page a link. It gives a quick way to reload the page.

Tom Kraak Tom Kraak says:

Erik - I don't think most "casual" users browse the web on that level.

Mitchel Sellers Mitchel Sellers says:

I finally got the tutorial that Tom was talking about posted today. Sorry for the delay. You can click on my name in this signature to go directly to the article.

Corinne Corinne says:

Hi Tom,
Great post! Couldn't agree more. Realize this is a long time after the fact, but any chance of getting the source for this skin object? Would like to use it and remove the last breadcrumb entirely - my client feels it is redundant as it repeats the page title.

Thanks in advance!
Cheers,
Corinne

Rodney Joyce Rodney Joyce says:

Good job Tom! I'll extend the skinobject for now - I raised this post in Gemini, hopefully they will add that property - http://www.dotnetnuke.com/Community/Forums/tabid/795/forumid/-1/postid/296420/scope/posts/Default.aspx

GAM GAM says:

Hello,
Please let me know, if you have any idea for Hide breadcrumb programmatically.

I need to hide breadcrumb from my Home page only.

Thank You.

Rodney Joyce Rodney Joyce says:

GAM - just make a copy of your home page skin and remove the breadcrumb for all the other pages.

Ken Tarwood Ken Tarwood says:

Heya Tom!

As you know I've been looking at little things I can do to boost our pageranks. I'd like to be able to add an H1 tag representing each page's name without changing our look & feel. I wondered if it would be worth it to write a custom breadcrumb skin object that wraps the last item in the trail with an H1 and just style it to make it look like the rest of the crumbs in the trail. We generally turn off container visibility (at least currently) and it seems duplicative to use a container heading for an H1 - especially as one can have multiple containers on a page.

Do you see any issues with this approach?


Thanks!
Ken

Rodney Joyce Rodney Joyce says:

Hi Ken,

There really should be only 1 H1 tag on the page and your main page title should be that one. I was reading a good book (Steve Krug - Don't make me think) and it was talking about this - every page needs to have a very visual identifier where it tells the user exactly what the main purpose of this page is.

Perhaps you need to step back and look at your page design again - if there are similar containers on the page they can use H2 headings, but there should be a grouping around that somewhere (H1) that sums up the page's overall purpose to the user. I recently faced the same issue on the PokerDIY.com skin redesign and how to handle this.

Tom Kraak Tom Kraak says:

Well put Rod.

@ Ken - there is no need for a custom skin object. Just put this into your skin:

<%=PortalSettings.ActiveTab.TabName %>

Tom Kraak Tom Kraak says:

<%=PortalSettings.ActiveTab.TabName %>

Name (required)

Email (will not be published) (required)

Website

Enter the code shown above:

Subscribe to our Feeds Follow on Twitter