Jack of all that is Microsoft, Master of None

May 9, 2008

WSS Navigation – Flyouts, Security Trimming & Custom Nav Items

I’ve been working with a client on a WSS site deployment, and one of our big sticking points has been with the out-of-the-box WSS navigation. The client set the following requirements for the navigation:

  1. Must be security trimmed – so if you don’t have access to a site, you don’t see it in the nav
  2. Must allow for the addition of custom navigation items
  3. Must have flyouts (drop-downs) that go at least 2 or 3 levels deep

Out of the box, we get #1 & #2, but since we’re not using MOSS, we can’t just modify the master page to get #3 to work.  That’s where my buddy the SharePoint Cowboy, Eric Shupps, found a nice way to add the drop-down menus to WSS.  The problem is that this approach switches the data source, and you lose the ability to specify what appears in the navigation.  So while you gain #3, you lose #2.  Talk about one step ahead, one step back.

So after some trial and error, some searching and enlisting the help of Josh Carlisle for a few lines of code, I have a solution…

The solution involves the following:

  1. Creating a WSS list that will manage you navigation.
  2. Implementing the Cascading Navigation web part from CodePlex.
  3. Adding a couple lines to your master page.
  4. Go wild!

So, in detail, here is what you need to do:

#1 – Setup your Navigation List

 The first thing you will want to do is create your navigation list.  It should be a Custom List, and I named mine ‘WSSNavigation’, but feel free to call yours whatever you would like.  I also do not display mine in the Quick Launch.  Once the base custom list is created, then create the following fields:

Note that for Item Level, your choices should only be Level 1, Level 2 or Level 3 (include spaces).

And for Display0 (make sure there is a zero!) the choices should be Yes or No.  Do not use a Yes/No field.

Now, go ahead and add a temporary line or two into the list.  Make sure that your Link ID is unique for each line… think of it as your primary key for each navigation item (it should just be an incrememental number… start at 1 and keep incrementing).  And if there is no parent of the item you are adding, keep that field blank.

#2 – Install the Navigation

Download the Cascading Nav WSP from CodePlex here:

http://www.codeplex.com/sharepointnavigation/Release/ProjectReleases.aspx?ReleaseId=9461

Install & deploy the solution package as you normally would.  Then, dump the web part on to a page & in the web part Miscellaneous properties, put in the name of the SharePoint list holding the navigation information under the Admin List field.  In my case above, I would input WSSNavigation.

If the navigation renders properly, then you are good to move on to step 3.  If it doesn’t, make sure you’ve put the in the correct name of the navigation list, and that each of the fields is set up properly. 

#3 – Modify the Master Page

So you’ve got the navigation working inside of a site in a web part zone – great.  Now, let’s replace the not so great out-of-the-box nav with our really cool nav.  Crack open the master page for the site, and insert the following line under the other lines that look the same (they will be at the top of the page and start with <%@ Register TagPrefix=):

<%@ Register TagPrefix=”customnav” assembly=”CascadingNav, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5″ namespace=”CascadingNav”  %>

 Then, let’s get rid of the old navigation by commenting it out.  Look for the following:

<asp:ContentPlaceHolder id=”PlaceHolderHorizontalNav” runat=”server”>
 <SharePoint:AspMenu
   ID=”TopNavigationMenu”
   Runat=”server”
   DataSourceID=”topSiteMap”
   EnableViewState=”false”
   AccessKey=”<%$Resources:wss,navigation_accesskey%>”
   Orientation=”Horizontal”
   StaticDisplayLevels=”2″
   MaximumDynamicDisplayLevels=”2″
   DynamicHorizontalOffset=”0″
   StaticPopoutImageUrl=”/_layouts/images/menudark.gif”
   StaticPopoutImageTextFormatString=””
   DynamicHoverStyle-BackColor=”#CBE3F0″
   SkipLinkText=””
   StaticSubMenuIndent=”0″
   CssClass=”ms-topNavContainer”>
  <StaticMenuStyle/>
  <StaticMenuItemStyle CssClass=”ms-topnav” ItemSpacing=”0px”/>
  <StaticSelectedStyle CssClass=”ms-topnavselected” />
  <StaticHoverStyle CssClass=”ms-topNavHover” />
  <DynamicMenuStyle  BackColor=”#F2F3F4″ BorderColor=”#A7B4CE” BorderWidth=”1px”/>
  <DynamicMenuItemStyle CssClass=”ms-topNavFlyOuts”/>
  <DynamicHoverStyle CssClass=”ms-topNavFlyOutsHover”/>
  <DynamicSelectedStyle CssClass=”ms-topNavFlyOutsSelected”/>
 </SharePoint:AspMenu>

Just before it, add <!- – Hide the original horizontal nav

and after it, add – ->

Then, on the next line after the line where you put the – ->, put in the following:

<customnav:CascadingNav runat=”server” id=”customNav” Set_AdminList=”WSSNavigation” __WebPartId=”{89DFF3CB-0E4A-4623-B69B-DFB818FBF6DB}”/>

Note that under Set_AdminList= make sure you input the name of your WSS List you created in Step 1 here.

#4 – Go Wild & Create your Menu

Your site should now be rendering the menu along with the navigational elements specified in the list.  Now, head back over to your list and build out your navigation.  As you add items to the list, your navigation will be updated, so you can quickly check and make sure things are looking good.  And remember – since the navigational items are essentially list items, you can set permissions on them individually.  Therefore, you can hide links from users that shouldn’t see them.

Enjoy,
Chris

 Technorati Tags:
, , , , ,

Advertisements

Create a free website or blog at WordPress.com.