Try our conversational search powered by Generative AI!

Single custom top menu for multiple plugins


Hi guys,

I have a small problem. I'm working on a few NuGet packages, and I need them all to appear under the same section. But I haven't been entirely successful with getting the menu to display my plugins properly. They tend to duplicate the section menu instead. So if I have 3 of my plugins installed, I'd end up with 3 duplicates of my custom section.

I'm using the MenuProvider to generate the menu items for my plugins. I first check whether the section already exists using MenuAssembler's GetMenuItems and add it using SectionMenuItem if it doesn't. However, during my debugging sessions, GetMenuItems returns 0 for all plugins. So the question is, why is it returning 0? Shouldn't the second time GetMenuItems is run return 1 as the section was added by the first plugin?

Have a look at a portion of my code below and please let me know what I did wrong.

public IEnumerable<MenuItem> GetMenuItems()
            var menuItems = new List<MenuItem> {};
            IEnumerable<MenuItem> sectionMenuItems = new MenuAssembler().GetMenuItems(MenuPaths.Global + "/mysection", 1);
            if (!sectionMenuItems.Any())
                var mainMenu = new SectionMenuItem("MySection"MenuPaths.Global + "/mysection") {IsAvailable = CheckAccess};
            var adminItem = new UrlMenuItem("My Plugin",
                                            MenuPaths.Global + "/mysection/myplugin",
                                            RootMenuUri + "/Admin/Default.aspx") {IsAvailable = CheckAccess};
            return menuItems;

All my plugins have this code. I hope someone can shed some light into this. I've spent a good amount of time trying to figure out what I did wrong before I gave up.

Thanks in advance.
May 10, 2012 15:33

I checked the code and there is actually no support for getting the already added menu items or merging items as I can see. My guess is that "new MenuAssembler()" will create a new instance that is not connected to the one calling the menu provider so that won't help you. I talked with Cristian Libardo that developed the menu and he suggested two alternatives:

1. Use HttContext or similar so set a static flag that the top menu item has been created.

2. Add the top menu item in web.config in your nuget setup.

Linus Ekström

May 15, 2012 10:13

Thanks for the answer. I've decided to go with option 1. Everything is working fine now.

May 15, 2012 13:44
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.