Skip to content

Instantly share code, notes, and snippets.

@perploug
Last active October 11, 2016 12:57
Show Gist options
  • Save perploug/7334403 to your computer and use it in GitHub Desktop.
Save perploug/7334403 to your computer and use it in GitHub Desktop.
how to hook into tree menus in V7
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Core;
namespace Meh.App_Code
{
public class ChangeMenu : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
Umbraco.Web.Trees.ContentTreeController.MenuRendering += ContentTreeController_MenuRendering;
}
void ContentTreeController_MenuRendering(Umbraco.Web.Trees.TreeControllerBase sender, Umbraco.Web.Trees.MenuRenderingEventArgs e)
{
//creates a menu action that will open /umbraco/currentSection/itemAlias.html
var i = new Umbraco.Web.Models.Trees.MenuItem("itemAlias", "Item name");
//optional, if you want to load a legacy page, otherwise it will just follow convention
i.AdditionalData.Add("actionUrl", "my/long/url/to/webformshorror.aspx");
//optional, if you dont want to follow conventions, but do want to use a angular view
i.AdditionalData.Add("actionView", "my/long/url/to/view.html");
//sets the icon to icon-wine-glass
i.Icon = "wine-glass"
//insert at index 5
e.Menu.Items.Insert(5,i);
}
}
}
@lars-erik
Copy link

I landed here from a google search. Would be nice if you added a sample with actionRoute too.

@kipusoep
Copy link

There's also "actionRoute", I needed it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment