May 8, 2012

That Darn Navigation!

Earlier, I have written about the two different global navigation controls that can be used in SharePoint 2010 MasterPages, the foundation (v4.master) version, and the publishing navigation. Essentially, they both come out the same, but then again not. In publishing navigation, you can quite easily hide the top level site link, as the site logo quite frequently serves that purpose and thus the link on navigation bar is most often more or less futile and takes up space. In the foundation navigation control, this cannot be done (as easily, maybe? so far I have not figured out a way).

Both controls can be used in any kind of MasterPages, whether targeted to publishing or foundation sites, as long as 
a) using the foundation navigation you are ok to display the top level site in the navigation or
b) using the publishing navigation you are either ok with always using the complete global navigation on team sites too, or configure the start node to be displayed and set the static display levels to 2 (otherwise the navigation will be empty when team sites don't use the navigation bar of parent site)

There is just one little problem with the publishing navigation, at least when using the CombinedNavSiteMapProvider, and same applies to GlobalNavSiteMapProvider. When using special characters, such as & marks in the site names, they get html encoded in the navigation bar,
e.g. Test & Try > Test & Try

In the publishing sites, i.e. publishing site targeted MasterPages, you can alternately use the CurrentNavigation as the sitemap provider, which does not have this character problem, but with the foundation sites, this again causes a problem, as Lists, Libraries, Discussions etc. start invading the top navigation!

Finally, after testing out different providers, I found that one option is to revert back to the one used in MOSS 2007: the GlobalNavigation. It works both in foundation and publishing sites, and supports both the special characters and hiding the top level site. So far, I know of no actual problems with it, so here you go:

<publishingnavigation:portalsitemapdatasource id="topSiteMap" runat="server" enableviewstate="false"
              sitemapprovider="GlobalNavigation" startfromcurrentnode="true" startingnodeoffset="0"
              showstartingnode="false" trimnoncurrenttypes="Heading" />
          <!-- top navigation menu (set to use the new Simple Rendering) -->
          <SharePoint:AspMenu ID="TopNavigationMenuV4" runat="server" EnableViewState="false"
              DataSourceID="topSiteMap" AccessKey="<%$Resources:wss,navigation_accesskey%>"
              UseSimpleRendering="true" UseSeparateCSS="false" Orientation="Horizontal" StaticDisplayLevels="1"
              MaximumDynamicDisplayLevels="0" SkipLinkText="" CssClass="s4-tn">
          </SharePoint:AspMenu>

Mind, that if you want the team sites to use their own instead ot parent's navigation, you still ought to use e.g. the foundation navi control or set the attributes to this navigation as stated earlier.  

No comments: