Friday, December 21, 2007

SharePoint: How to make navigation headings inherit to subsites

I've seen several messages on newsgroups and the web about this problem. You set up "current navigation" on some site, and you want all of the subsites to have the exact same navigation. The problem is, if you include "headers" in your top-level navigation, they (as well as the links underneath them) do not appear in the navigation of subsites, no matter how much you play with the navigation in the subsites. I'm not sure if this is a bug or if it's by design. I haven't tested the following solution in multiple situations but it might work for you.

1. Add this assembly reference to the master page of the level where you want to supply the authoritative navigation:

<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

2. Add the following PortalSiteMapDataSource definition to the same master page:


<PublishingNavigation:PortalSiteMapDataSource
ID="SiteMapDSWithHeadings"
Runat="server"
SiteMapProvider="CurrentNavSiteMapProvider"
EnableViewState="true"
StartFromCurrentNode="true"
StartingNodeOffset="0"
ShowStartingNode="false"
TrimNonCurrentTypes="None"
EnableInheritance="True"
/>



3. Find the line that says

<SharePoint:AspMenu id="QuickLaunchMenu" DataSourceId="QuickLaunchSiteMap" runat="server" Orientation="Vertical" StaticDisplayLevels="2" ItemWrap="true" MaximumDynamicDisplayLevels="0" StaticSubMenuIndent="0" SkipLinkText="">

(i.e. the line that begins the definition for your quick launch control).

Change the DataSourceID from "QuickLaunchSiteMap" to "SiteMapDSWithHeadings".

4. Make sure your subsites inherit their master page from parent.

5. In your subsites, under Site Settings->Modify Navigation, set Current Navigation to "Display the same navigation items as the parent site."

Your subsites should now inherit all of the links and headings from the Current Navigation of their parent.

14 comments:

Richard said...

I was going crazy trying to figure out why my subsite navigation wasn't inherited the way I thought it would!

You would think the SharePoint MOSS 2007 setting: Look and Feel > Navigation > Current Navigation > Display the same navigation items as the parent site (especially with that little icon with the quick launch highlighted there) would mean that the parent site navigation is inherited by the child site navigation. Who knew you had to hack the code to get this to work!

This is a major timesaver and was very timely, thanks!

-Richard.

scorpion_prince said...

Hi Thomas,
Thanks for the excellent article, I was able to implement the this on a site collection and it works wonderful. However, the quicklaunch navigation was not inherited by Team Sites or Blank Sites or Wiki Sitesl it worked only on sites using the Publishing template. Is it something I'm missing or is it a SharePoint limitation?

Thanks,
Prabin Varma

ThomasA said...

Hmmm... I developed this in a publishing context. I've never tried it for other types of sites, so it could very well be a SharePoint limitation. But my intuition says some variant of the master page modifications should work for other types of sites.

Lisa Jeffares said...

Thank you so much for that, it saved me a lot of time. Great post.

Unknown said...

I think is from this property of the PortalSiteMapDataSource: TrimNonCurrentTypes="None". By default is set to Heading. After i changed to None, all works.

PublishingNavigation:PortalSiteMapDataSource ID="SiteMapDS" ... TrimNonCurrentTypes="None"

Unknown said...

Many thanks for article Thomas! Was great help for me.

Jesper Arent said...

Anyone who has made it work on Blank sites as well?

Just to hear before I dig into it...

Jesper Arent said...

I imagine you need to choose another assembly than Sharepoint.Publishing, but which?

ThomasA said...

Sorry, I don't have the resources to try to reproduce the problem in blank sites. I strongly suspect the solution would involve finding the non-publishing equivalent of PublishingNavigation:PortalSiteMapDataSource and substituting that for step 2.

Thomas

Ivan Wilson said...

Nice post. This worked for me, but then I enabled anonymous access for the web application and site collection.

Now the navigation only appears at the top site. The sub-sites have no current navigation (apart from "View all site content")

Once I sign in, the navigation displays on the subsites again.

Any idea what I should change to allow the navigation to show up for anonymous users?

ThomasA said...

Ivan,
Could it be permissions? Do anonymous users have access to everything at the top site?

Unknown said...

Hi Thomas,

I just want to say thanks so much for posting this article it saved me a lot of frustration and headaches

VoIP Dude said...

Hi.
I'm a kind of newbie.

Where, in the master page (default.master), I put the code of section #2?

I put the code in section #1 in the header, before the "HTML" tag.

For the #3, I find the location and replace the code.

But wonder were to place the section #2 code in the default.master page!

Many thanks!

Joël.

Larry said...

This is a great tweak. I too was beating my head against a wall wondering why SharePoint makes it difficult to do logical things...:)