How To Add A Link Into The QuickNavigatorMenu in Episerver

In today's guide I'm going to cover how to customise Episerver quick navigator. With the release of Episerver 7 came with the new Quick Navigator Menu, as seen below: episerver_quick_navigation_menu When you log into the editor with a user, it should pop-up in your site as long as you've added the Render tag in your layout:

  @Html.RenderEPiServerQuickNavigator()
To make life a little bit easier, from your content editors you can add your own links in the Quick Navigation bar and the process is pretty simple.  You start off creating a class that implements IQuickNavigatorItemProvider interface and has the [ServiceConfiguration(ServiceType = typeof(IQuickNavigatorItemProvider))] attribute defined. You will need to implement the GetMenuItems method which returns a IDictionary<string, QuickNavigatorMenuItem>. In this method you simply create a list and add QuickNavigatorMenuItem into it,then return it. Below defines a simple code snippet that adds a link to the StartPage.
using System.Collections.Generic;

using EPiServer.Core;
using EPiServer.ServiceLocation;
using EPiServer.Web;
using EPiServer.Web.PageExtensions;

using GMGShop.Domain.DependencyResolver;
using GMGShop.Model.ConfigurationResolver;
using GMGShop.Model.PageTypes;

namespace GMGShop.Model.QuickNavigatorMenuItems
{
    [ServiceConfiguration(ServiceType = typeof(IQuickNavigatorItemProvider))]
    public class CustomQuickNavigator : IQuickNavigatorItemProvider
    {
        private int sortOrder = 50;

        public int SortOrder
        {
            get
            {
                return sortOrder;
            }
            set
            {
                sortOrder = value;
            }
        }

        public IDictionary<string, QuickNavigatorMenuItem> GetMenuItems(ContentReference currentContent)
        {
            var repository = ServiceLocator.Current.GetInstance<IContentRepository>
            var startPage = repository.Get<StartPage>(PageReference.StartPage);

            var quickNavItem = new QuickNavigatorMenuItem("Homepage", pageReference.LinkURL, null, null, null);

            var menuItems = new Dictionary<string, QuickNavigatorMenuItem>
                                {
                                    {
                                        "qn-homepage-manager",
                                        quickNavItem
                                    }
                                };

            return menuItems;
        }
    }
}


Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge


Back to top
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-35662136-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();