Summary
Requirements:
- SharePoint MOSS 2007
- Must be using a Publishing Site
This post will create the SharePoint Current Navigation control that only shows the 2nd level site when browsing, and supports highlighting. The datasource comes from SharePoint as well, so everything is security trimmed, and editable in the browser.
This post is for users who are using SharePoint MOSS 2007 navigation on their website. If you want your current navigation to display the sites and pages under a subsite, but always keep the second level subsite on top, then this post is for you. It’s hard to explain, so reference the screenshot below:
Figure 1 – Our Firm is a subsite under the root of the website. Even if I navigate to Board of Directors above, Our Firm remains at the top of the Current Navigation.
Sitemap data for my screenshot above:
-
Company
-
Our Firm
-
Leadership
- Management Team
- Board of Directors
- Contact Us
- Locations
-
- Investment Banking
- Sales & Training
- Research
-
Sitemap levels:
-
Top Level (root)
-
Second Level site
-
Third Level Site
- Fourth Level site
- Fourth Level site
- Third Level Site
- Third Level Site
-
- Second Level site
- Second Level site
- Second Level site
-
The key is that I want only each second level navigation block to appear when a user is anywhere on or under that second level site. So in my screenshot, you see Our Firm, even if you navigate to Board of Directors.
This navigation also supports highlighting and pages.
Preparing the subsite (our Firm)
- Check Show Subsites and Show Pages
- Under Current Navigation, select Display current, below, and siblings. (the middle radio button)
Now you need to adjust your current navigation code in the MASTERPAGE to only show the site you are under.
Adjusting the masterpage Current Navigation
Find your PlaceHolderLeftNavBar and replace the contents with this, or you can just mimic it. Take note of the highlighted parts. These are important for this post.
Placeholders are content buckets in your masterpages, the content inside them is what is important. Just make sure you don’t have multiple of the same ID’s on the same masterpage.
Here is the code:
<asp:ContentPlaceHolder id=”PlaceHolderLeftNavBar” runat=”server”>
<!– Current Navigation –>
<!– Current Navigation –>
<SharePoint:AspMenu ID=”CurrentNav” runat=”server” datasourceID=”SiteMapDS” orientation=”Vertical”
StaticDisplayLevels=”4″ MaximumDynamicDisplayLevels=”1″ StaticSubMenuIndent=”1″ ItemWrap=”true”
AccessKey=”3″ CssClass=”leftNav” SkipLinkText=”<%$Resources:cms,masterpages_skiplinktext%>”>
<StaticHoverStyle CssClass=”LeftStaticHover” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />
<StaticSelectedStyle CssClass=”LeftStaticSelected” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />
<DynamicMenuStyle CssClass=”LeftDynamicMenu” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />
<DynamicMenuItemStyle CssClass=”LeftDynamicMenuItem” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />
<LevelMenuItemStyles>
<asp:menuitemstyle CssClass=”parent” Font-Underline=”False” />
<asp:menuitemstyle CssClass=”child” Font-Underline=”False” />
<asp:menuitemstyle CssClass=”leftNav3″ Font-Underline=”False” />
<asp:menuitemstyle CssClass=”leftNav4″ Font-Underline=”False” />
<asp:menuitemstyle CssClass=”leftNav5″ Font-Underline=”False” />
</LevelMenuItemStyles>
<StaticMenuStyle CssClass=”LeftStaticMenu” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />
<DynamicSelectedStyle CssClass=”LeftDynamicSelected” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />
<StaticMenuItemStyle CssClass=”LeftStaticMenuItem” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />
<DynamicHoverStyle CssClass=”LeftDynamicHover” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False”/>
</SharePoint:AspMenu>
<PublishingNavigation:PortalSiteMapDataSource ID=”SiteMapDS” Runat=”server”
SiteMapProvider=”CombinedNavSiteMapProvider”
StartFromCurrentNode=”True”
StartingNodeOffset=”1″ TrimNonCurrentTypes=”Page”/>
</asp:ContentPlaceHolder>
Here is an explanation of the above code:
SharePoint:AspMenu | Creates an ASP.Net menu (html) using tables |
datasourceID | This sets the Datasource to populate the HTML. In this case, it points to the ID of the PublishingNavigation:PortalSiteMapDataSource. |
StaticDisplayLevels | How many levels to display (non flyouts) starting from the data returned. If your datasource only returns second level sites, the ASP Menu sees these as the first level. |
MaximumDynamicDisplayLevels | 1 disables flyouts. 2 would have the 5th level links as a flyout. |
Datasource properties
PublishingNavigation:PortalSiteMapDataSource | Creates a datasource on our page. This control uses the SharePoint Navigation. |
ID | Sets the ID of this datasource for ASP.Menu or other controls to access the data |
SiteMapProvider | There are a lot. I really like CombinedNavSiteMapProvider for this blog post. It was the best I found. Here are a few more |
StartFromCurrnetNode | Not sure why, but I think this controls the highlighting of sub sites. If this is set to false, I think the returned data source does not know what site you are located in. More here |
StartingNodeOffset | This is the reason why we see the second level page at the top of our left navigation, and not the root. We trim the root, as 0 is default, but we specify 1. This trims one level off our data source. See a full explanation here |
TrimNonCurrnetTypes | Since we specify pages, this removes all pages from the datasource that are not under the current site, and not below. See here for more info |
See this same table (and ALL OTHER PROPERTIES!) here: http://msdn.microsoft.com/en-us/library/bb897657.aspx
Basically, just play around with the code. You can learn a lot just modifying the above properties. I basically wanted this blog post to show a neat configuration of SharePoint navigation 🙂
Good luck!
Is there a way to do this in SharePoint 2010? I have been trying to find a way for weeks to adjust my left navigation (QuickLaunchSiteMap) that displays 3 static levels to only display three on the selected node like your example above? any ideas? suggestions?
You can try:
SharePoint:AspMenu id="V4QuickLaunchMenu" runat="server"
EnableViewState="false" DataSourceId="QuickLaunchSiteMap"
UseSimpleRendering="true" UseSeparateCss="false" Orientation="Vertical"
StaticDisplayLevels="4" MaximumDynamicDisplayLevels="1"
SkipLinkText="" CssClass="s4-ql"
But the
QuickLaunchSiteMap
datasource might not keep track of the current page you are on likeSiteMapDS
does.Will do. Thanks for the quick response. The only reason i did not use SiteMapDS was because i get an error when i try to use it. Any idea on why SiteMapDS is not working on SP2010?
You can use any datasource prefixed with “Current” as far as I remember. Intellisense or googling a few of the datasources should lead you to all of your choices.
Your’e a genius! You wouldn’t believe how many times I tried to do this and always gave up on it in the end. I can’t believe it’s that simple.
Actually, now that I tested it for a bit I realised it doesn’t quite work for me.
I have got a menu that looks like this:
Section 1
– Subsection 1.1
Section 2
– Subsection 2.1
The menu looks the same no matter where in the site the user is. I expected the section that the user isn’t in to be “collapsed”. So if a user is in Section 2 or Subsection 2.1 I thought the menu would look like this:
Section 1
Section 2
– Subsection 2.1
But that doesn’t happen. Any idea where I am going wrong?
per our email, looks like SharePoint 2010 navigation sources that start with “Combined…” behave differently than in SharePoint 2007. They may have added more properties to navigation controls. (Google SharePoint:ASPMenu and PublishingNavigation:PortalSiteMapDataSource, also make sure publishing features are tuned on, or you are using a publishing site template)
Where I can find the css file for this navigation?
This post is for the ASP.NET control rather than styling. You will have to do a CSS trace using IE Developer Toolbar on the navigation.
I have done the navigation on QuickLaunch Menu following this post. Which is the url to trace css file using IE Developer Toolbar. Thank you
I have done the navigation on QuickLaunch Menu following this post. Which is the url to trace css file using IE Developer Toolbar. Thank you