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

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *