Last active
October 11, 2016 12:57
-
-
Save perploug/7334403 to your computer and use it in GitHub Desktop.
how to hook into tree menus in V7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
There's also "actionRoute", I needed it :-)