This post is part of a series of posts… jump to the overview post that explains what it is all about and to get links on all the other posts here: SharePoint 2010 Metadata-Based Navigation in Publishing Sites - Series Overview.
I’m guessing that if you are reading this post you likely read the one before it where I talked about the virtues of implementing a MetaNav. In this post I’m going to talk about what you’re going to have to build in order to implement a MetaNav in your SharePoint 2010 (SP2010) Publishing site (aka: WCM site). At the core there are three major things you have to address:
- Rollup/Landing Pages & Controls
- Detail Pages
It wouldn’t be a MetaNav if you didn’t have navigation now, would it? Of course not. SP2010 implements navigation by leveraging the ASP.NET Navigation Provider framework. In this there are three main components:
- Navigation Provider - This piece is responsible for talking to some entity and creating the hierarchical collection of navigation nodes. Some out of the box providers include those that can look at an XML file or a SharePoint site. In our case we need to create one that looks at the SP2010 Managed Metadata Service (MMS) to extract a taxonomy.
- Data Source - The data source control is responsible for obtaining the navigation hierarchical structure from the navigation provider & figuring out what nodes should be included in the rendering… it essentially is filtering the nav. From here you do things like tell it to start at the top-most node or the current node, if the top-most node should be shown and things of that nature.
- Navigation Web Control - This control takes what the data source has filtered down and renders it out to HTML. From here you do things like control the CSS, indention and things of that nature.
As far as a MetaNav is concerned, there’s only one thing you need to build: a new navigation provider. As I said above, the job of this provider is to look at the taxonomy and build a collection of navigation nodes representing it. This is actually fairly easy to do as you’re just building an ASP.NET navigation provider.
Create a new class that inherits the PortalSiteMapProvider from the Publishing namespace and override just one method: GetChildNodes(). Then fill this method with the following code. This gets called for every node you create and it has the sole responsibility of returning the immediate child nodes under it. As you can see from the following class, I check to see if we’re at the top node and if we are, we start at the top of the taxonomy. Otherwise it’s a GUID, the ID of the term in the nav I created, I find the term in the term set & get all it’s children.
After building the project and deploying the DLL to the GAC, you next need to register the provider. Add the following to the element collection in the site’s web.config. This makes the site aware of the provider.
Lastly, you change the data source in the master page or where ever you are using it and poof, you got it working! From the pictures below, you can see the taxonomy on the left and the nav on the right:
Sometimes your navigation has the actual detail page links in them, but all the time your navigation points to rollup or landing pages. The goal of these rollup/landing pages is to present links to the other pages in your site. These pages (which could contain reusable controls) work best when you leverage search to find the pages that match the criteria on the landing page.
Below I’ve used a Web Part to show how to build the rollup. It is checking the taxid QueryString parameter to find out what term was passed along. Here’s what it looks like:
Generally there isn’t much of a problem in having to set this up. The pages are created like normal and the links to them will be visible in the search results. Thus when you create the rollup pages & controls, you’ll just link to these detail pages. However if you want to show content not just from your site collection, but also from other site collections If you want to show pages that don’t live in the site collection, such as those that live in another site collections or outside SharePoint. I doubt you’ll want to redirect your users from your site to wherever this content lives… you’ll likely want to surface the content in your site to maintain your user experience. One way to address this is to create your own version on the profile page capability that Business Connectivity Services (BCS) offers.
You can grab the source code to a sample MetaNav from the Critical Path Training site, specifically the Members section after you login (which is free). Look in the Code Samples section for AC’s SharePoint 2010 Sample MetaNav for Publishing Sites.comments powered by Disqus