-
-
Save RyanABailey/da246177a34bad22158b to your computer and use it in GitHub Desktop.
Navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Navigation.ascx.cs" Inherits="MySitecoreSite.Sublayouts.Navigation" %> | |
| <ul class="nav navbar-nav navbar-right"> | |
| <asp:Repeater ID="rptMenu" runat="server"> | |
| <itemtemplate> | |
| <li> | |
| <a href="<%# Eval("Link") %>"><%# Eval("Text") %></a> | |
| </li> | |
| </itemtemplate> | |
| </asp:Repeater> | |
| </ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using Sitecore.Data; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Web; | |
| using System.Web.UI; | |
| using System.Web.UI.WebControls; | |
| namespace MySitecoreSite.Sublayouts | |
| { | |
| public partial class Navigation : System.Web.UI.UserControl | |
| { | |
| protected void Page_Load(object sender, EventArgs e) | |
| { | |
| var menuItems = new List<NavMenuItem>(); | |
| Database current = Sitecore.Context.Database; | |
| var mainContentItem = current.GetItem(new ID("{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}")); // Uses GUID of main Content item | |
| var items = mainContentItem.GetChildren().ToList().Where(x => x.Fields["TopMenu"].ToString() == "1"); | |
| foreach (var item in items) | |
| { | |
| menuItems.Add(new NavMenuItem | |
| { | |
| Link = Sitecore.Links.LinkManager.GetItemUrl(item), | |
| Text = item.Name, | |
| }); | |
| } | |
| rptMenu.DataSource = menuItems; | |
| rptMenu.DataBind(); | |
| } | |
| public class NavMenuItem | |
| { | |
| public string Link { get; set; } | |
| public string Text { get; set; } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment