Limiting the levels shown in SharePoint Breadcrumbs

This was such a good question, I thought I’d reply in a post about it:

I am trying to limit the depth of the breadcrumbs. I have a sub sub sub subsite that I want breadcrumbs to show from that site and down one more level. I can make the breadcrumbs invisible using SPD but I wonder if I can make them limited … like we could in WSS 2. – Jo Arnspiger

Well, there are a couple of ways that spring to mind (there are many approaches, but these are probably the best two) – one that uses SharePoint Designer, and one that uses SharePoint’s own navigation configuration.

First off, let’s look at the SharePoint Designer route. If you go to your master page or page layout, you’ll see an ASP control called the SiteMapPath control. It has a property called ParentLevelsDisplayed.

A SiteMapPath control showing the ParentLevelsDisplayed property.

Set that to a number, and that should be the maximum number of levels shown. If you set it to -1, it will show however many levels there are, which is it’s default. (I’ve not tried it, but I’m pretty sure that’s the case). That’s probably what you want, but there is a problem – it’s not just your master page which defines the SiteMapPath control. There is one on most of the Publishing Page layouts that come out of the box too. Still, if you’re happy taking a little time to change all of them, then that’s probably fine.

The other problem is a little more fundamental – this setting will apply across your entire site collection. Well, okay, maybe not, but it’ll apply for all pages using that master page or page layouts…

Alternatively, you could change the Site’s navigation settings to get what you want. At the ‘sub sub sub subsite‘ you could change the site’s navigation setting to not inherit it’s top navigation settings from the parent site. This will add a level to the ‘Global Navigation’ breadcrumb, but also make all URLs below the ‘sub sub sub subsite‘ start at that level. See my previous article for an explanation.

The down side about this approach, though, is that it means all of your top navigation tabs will change – you really are breaking with the ‘navigation context’ of the parent site. (That’s my term – I didn’t know what else to call it.) There is an example of this on the article linked to above.

A final note, these approaches do have two slightly different results – the first route is a ‘only show the last X items’, while the second is ‘chop all breadcrumbs below this site to start here’.

Anyway Jo, I hope that one of those is suitable.

Limiting the levels shown in SharePoint Breadcrumbs

Breadcrumb Path Separator and Path Direction

There are several settings you can apply to breadcrumbs in MOSS, although really some of these are really ASP.NET settings rather than most specific. Previously I’ve mentioned using different SiteMapProviders and rendering the current location as a link. Let’s have a look at another couple of settings:

Examples of various breadcrumb settings and different SiteMapProvider's output

(Yes, this screenshot shows some other settings – they’re mentioned in the other articles)

Looking at the screenshot we can see how the Path Separator setting allows us to set what we want shown between nodes – rather than ” > ” I’ve used “:”. Not sure when/why you’d want to change that, but I’m sure I’ll be given a design where that is useful sometime!

There’s also the Path Direction setting, which allows us to set whether the breadcrumb should have the current node on the left or right of the breadcrumb – hence the two settings, RootToCurrent and CurrentToRoot. Note, though, that the default path separator doesn’t swap from ” > ” to ” < “.

Breadcrumb Path Separator and Path Direction

Breadcrumbs – Rendering the current link

So one of yesterdays posts brought up a question about rendering the link to the current site. This sort of set me investigating.

There are a number of settings you can use with the ASP:SiteMapPath control. One is the RenderCurrentLink option. This defines whether the current location indicator in the breadcrumb should be shown as a link.

Examples of various breadcrumb settings and different SiteMapProvider's output

(Yes, this screenshot shows other settings – I’ll discuss them in other posts)

Looking at the top 4 rows you can see the effect of the the RenderCurrentLink option – it determines whether the last item is displayed as a link or not.

Breadcrumbs – Rendering the current link

My Breadcrumbs have "> Pages > default.aspx" in them

I’ve written about this before, but really it was just an addendum to another point I was trying to make. It might be worth bringing out as a post in itself.

ASP.NET navigation controls take data from a navigation provider, and render it into HTML. The breadcrumbs used in SharePoint use the one navigation control, but give it different navigation providers…

… the point relevant to whether or not the “> Pages > default.aspx” is displayed in the breadcrumbs is the SiteMapProvider. The CurrentNavSiteMapProviderNoEncode provider doesn’t seem to include the ‘Pages’ bit of the path – hence it is used by the page layouts. The Default.master’s SPContentMapProvider provides a breadcrumb that includes the ‘Pages’.

So, if your page is using a breadcrumb such as…

<asp:SiteMapPath id="ContentMap" SiteMapProvider="SPContentMapProvider" SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional" runat="server"/>

… then your breadcrumb will include the “> Pages > default.aspx”. Note that this is the default content of the breadcrumb in default.master. Thus, if you’re creating a brand new page layout, you’ll probably want to override that content using an ASP.NET Content control something like this…

<asp:Content ContentPlaceHolderId="PlaceHolderTitleBreadcrumb" runat="server">

<asp:SiteMapPath ID="siteMapPath" SiteMapProvider="CurrentNavSiteMapProviderNoEncode" RenderCurrentNodeAsLink="false" SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional" Runat="server"/>

</asp:Content>

This code defines a content control that overrides the default content for the Title Breadcrumb. It uses the CurrentNavSiteMapProviderNoEncode (nice name!) navigation provider, and so won’t show the “> Pages > default.aspx” bit in the breadcrumb.

So, in short, when you’re creating a new Page Layout, make sure you override the Title Breadcrumb with something that uses the CurrentNavSiteMapProviderNoEncode provider.

My Breadcrumbs have "> Pages > default.aspx" in them

Are SharePoint Breadcrumbs completely wrong?

I upgraded the version of WordPress I’m running recently and I enabled statistics on the blog. It’s been a bit of an eye-opener. My posts on ‘What the heck is going on with SharePoint Breadcrumbs‘ and ‘More SharePoint Breadcrumbs WTF‘ have together more hits that any of my other articles, and both are visited about evenly.

This is pretty interesting. Breadcrumbs should be pretty simple. I mean, we all use them on the web, probably every day, and often without noticing. So how come people are clearly looking up information about SharePoint breadcrumbs? Clearly something is wrong with them.

So this set me thinking – what’s wrong with them? And here’s what I could think of:

  • There are two breadcrumbs. You’ve got the Global breadcrumb, and then the PlaceholderTitle breadcrumb. Seriously, how many websites do you come across that have two?
    Image showing the Global and Title Breadcrumbs
  • ‘Site’ levels of the hierarchy can appear in one or the other breadcrumb. Depending on whether or not your navigation inherits it’s navigation from it’s parent site, the ‘Site’ links can appear in the global or title breadcrumbs. Thus, there’s no consistency as to where a site appears – if it appears at all! I can see why it’s been built this way – essentially it allows us to ‘skip’ levels in the site hierarchy as shown on the global breadcrumb, and it shortens the title breadcrumb. I wonder if this wouldn’t be better facilitated by a ‘show in Global breadcrumb’ site setting. Or just show all sites in the path to the site?
  • Why is what is shown in the breadcrumbs tied to what is shown in the site’s top navigation? That’s just confusing.
  • Having some breadcrumbs in the Page Layout (i.e. in the main content area) and others coming from the master page is just plain confusing.

I don’t quite know what the answer to this is; after all, we need a way to navigate back up the site hierarchy, though we might not always want to allow that. And breadcrumbs could get very long, so yes, maybe we want to skip levels. But I think I’d be tempted by showing all sites in the Global navigation. This would also divorce the breadcrumb from the top navigation settings, and I think would be easier.

And if the Global navigation gets too long? Well, that seems quite possible. In that case, how about a setting on each site to ‘Display in Menu in the Breadcrumb’ to give something like this:

Concept of single breadcrumb using drop down menus

This way you can still have your ‘Main’ sites in the hierarchy, but all levels are still available. Of course, you might want to make it that all the subsites of last ‘Main’ site are always visible irrespective of that setting. I think that would work, and would require less getting used to.

It’s a bit like the Vista breadcrumb in Windows Explorer – but a bit different, which might count against it…

The breadcrumb in Windows Explorer in Vista

That said, I’m open to thoughts from others! Comment if you’ve got an idea of how breadcrumbs should work!

Are SharePoint Breadcrumbs completely wrong?

Folder based Navigation in SharePoint

We have a customer who wants a fairly simple site – all it needs to be is a heirarchy of web pages.

Unfortunately, SharePoint Publishing features don’t really do this very well. Yes, in a document library it does breadcrumbs as you navigate through folders – but you can’t really do that with Pages. For a start, you can’t put folders in pages libraries!

So, instead, they’ve got this deep structure of sites – just to get the navigation. The site permissions and features are the same at all levels. This is a real administrative pain – especially if want to change the definition of the content types used in the pages libraries throughout the site.

What would be better would be to have navigation providers which show Folders in the navigation – so that they’re exposed in the left navigation (and maybe the top – I’m not sure). You could then enable folders in your page library. Users would then be able to navigate down through folders and pages. I guess there is a question as to which page should be the ‘default’ for a folder (obviously the folder itself isn’t a page that can be shown) – but perhaps something like just having a convention that the page ‘default’ is shown would be enough. Or maybe make it part of the metadata for a ‘Publishing Folder’ content type.
This would mean that the whole deep heirarchy and dozens of sites my customer is using could be dealt with in one single site. I can’t quite believe that nobody had this idea when they were planning the WCM features for MOSS. I don’t even think it’d be that hard – I just hope that I get a chance to implement this sometime…

Folder based Navigation in SharePoint

Page Layouts, Breadcrumbs, and the space above the main content area of a page.

Previously, I’ve blogged about some of my investigations into how breadcrumbs work in SharePoint – and how sometimes they’re shown in the ‘Page Title Area’, and sometimes they’re put into the ‘Main Content Area’.

One of our customers was building a page layout, and wanted the breadcrumbs inside the Main content area. They put the following content controls into the page layout file:

<%-- This content tag blanks the 'title' placeholder, which is above the white 'main content area' of a page --%>
<asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" />

<%-- This content tag blanks the 'title breadcrumbs' placeholder, which is above the white 'main content area' of a page --%>
<asp:Content ContentPlaceHolderId="PlaceHolderTitleBreadcrumb" runat="server"/>

<%-- This is the main content for a page. This content tag is an example only.
Usually there is more formatting and web part zones, other controls, etc.--%>

<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">

<!-- This tag defines the breadcrumb to display. On a normal page (such as defaultlayout.aspx) it is a contained within a table -->
<asp:SiteMapPath ID="ContentMap" Runat="server" SiteMapProvider="CurrentNavSiteMapProviderNoEncode" RenderCurrentNodeAsLink="false" SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional"/>

<!-- This tag displays the text of the page's 'Title' that is given when it is created. -->
<SharePoint:FieldValue id="PageTitle" FieldName="Title" runat="server"/>

</asp:Content>

Unfortunately, this resulted in a gap between the top of the page content area, and the bottom of the top navigation:

Page Layout Gap

So, what was missing?

Well, it turns out that another couple of content controls are relevant:

<asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server"><IMG src="/_layouts/images/blank.gif" width=1 height=1 alt=""></asp:Content>

<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<style>
TD.ms-titleareaframe, .ms-pagetitleareaframe {
height: 10px;
}
Div.ms-titleareaframe {
height: 100%;
}
.ms-pagetitleareaframe table {
background: none;
height: 10px;
}
</style>
</asp:Content>

The first content tag blanks the ‘page icon’ placeholder, which is above and to the left the white ‘main content area’ of a page. It is set to show a 1 pixel transparent image, and it appears that this is to maintain page structure, where setting the content to nothing might allow the table cell to collapse. And I thought that 1 pixel transparent gifs were so 1992.

The second content tag reduces the space available for the ‘page title area’ through CSS. It overrides some of the styles to do this. Of course, this relies on your master page using those styles, or having that structure – so if you’re planning on creating a custom master page, you’d better think of all custom page layouts too. I’m not really convinced about that as design – it seems to me that this makes creating a new, radically different master page even harder, as the page layouts must be rebuilt too.

Page Layouts, Breadcrumbs, and the space above the main content area of a page.