Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented May 19, 2014

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

@kipusoep

This comment has been minimized.

Copy link

commented Oct 31, 2014

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
You can’t perform that action at this time.