Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NathalieLarsson/192e8686540cbd67e0cb24763a9da5bf to your computer and use it in GitHub Desktop.
Save NathalieLarsson/192e8686540cbd67e0cb24763a9da5bf 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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment