Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OllyHodgson/7f50e5ed4f6d16f630bde8a1556fb6bc to your computer and use it in GitHub Desktop.
Save OllyHodgson/7f50e5ed4f6d16f630bde8a1556fb6bc to your computer and use it in GitHub Desktop.
SharePoint 2010 top level navigation code. Built with a nested ASP:Repeater control. Easier to style with Bootstrap or Flexbox than the ASP:Menu control. Includes highlighting of the current section.
<!-- top navigation publishing data source -->
<PublishingNavigation:PortalSiteMapDataSource
id="topSiteMap"
runat="server"
EnableViewState="false"
SiteMapProvider="GlobalNavigation"
StartFromCurrentNode="false"
StartingNodeOffset="0"
ShowStartingNode="true"
TrimNonCurrentTypes="Heading"/>
<!--
Repeater outputs a single level list of top-navigation.
Sets class="selected" on the current page / site.
This is much easier to adapt to use with Bootstrap or flexbox than the asp:menu control.
Based on a post by Bhavin Prajapati - http://sharepoint2010customnavigation.blogspot.co.uk/2011/05/create-custom-navigation-for.html
-->
<asp:Repeater runat="server" ID="MenuRepeater" DataSourceID="topSiteMap">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<SeparatorTemplate></SeparatorTemplate>
<ItemTemplate>
<li>
<a href="<%# Eval("Url")%>"
class="<%# (Request.RawUrl.ToString().ToLower().Split('/')[1] == Eval("Url").ToString().ToLower().Split('/')[1]) ? "selected" : "" %>">
<%# Eval("Title")%>
</a>
</li>
<asp:Repeater runat="server" ID="ChildMenuRepeater" DataSource='<%# ((SiteMapNode)Container.DataItem).ChildNodes %>'>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<li>
<a href="<%# Eval("Url")%>"
class="<%# (Request.RawUrl.ToString().ToLower().Split('/')[1] == Eval("Url").ToString().ToLower().Split('/')[1]) ? "selected" : "" %>">
<%# Eval("Title")%>
</a>
</li>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment