Navigation in SharePoint is not just a set of links that you can`t leverage; you can actually connect to a navigation DataSource called
PortalSiteMapDataSource and render your navigation depending on your custom logic or design requirements. If you`re using SharePoint in Public website scenario or have a complex design requirements when creating an intranet - navigation will likely to be one of the first things that end users would like to change.
To keep things separate and clean in your solution, it`s best if you seal your custom navigation logic and presentation into a custom control and then reference your custom control either on the master page or on the associated layout.
In our case we`ll create a user control later placed inside a page to render navigation with our unique design properties. Our control will first include standard references to SharePoint
<%@ Register TagPrefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”PublishingWebControls” Namespace=”Microsoft.SharePoint.Publishing.WebControls” Assembly=”Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”PublishingNavigation” Namespace=”Microsoft.SharePoint.Publishing.Navigation” Assembly=”Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”SharePointWebControls” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
Then we`ll create an instance of
PortalSiteMapDataSource with specific properties denoting which is our starting node and any navigation node offset:
<PublishingNavigation:PortalSiteMapDataSource id=”LeftNavDS” runat=”server” sitemapprovider=”CombinedNavSiteMapProvider”
enableviewstate=”true”
startfromcurrentnode=”true”
startingnodeoffset=”3″
showstartingnode=”false”
trimnoncurrenttypes=”Heading” />
Lastly, we create our navigation control which is going to connect to earlier established DataSource:
<div class=”myNav”>
<RecursiveULNavigation id=”RecursiveNavigation” runat=”server”
firstitemcssclass=”first”
lastitemcssclass=”last”
haschildrencssclass=”hasChildren”
selecteditemcssclass=”selected”
datasourceid=”LeftNavDS” />
</div>
Few things to explain above code:
1. We have our navigation control wrapped in DIV to make it easier to separate it from other design elements on the site.
2. You can define styles for your elements, including SELECTED ITEM state by using associated stylesheet.
Now, all you need is to call a user control in your layout or masterpage.
Yaroslav Pentsarskyy, Microsoft MVP
Blog:
www.sharemuch.com