Manager Menu

Last Updated: 2018-10-14

When adding new functionality to the manager you'll want to add items for your new page in the menu. The menu is a static singleton object that can be changed or updated from anywhere, at any time. However, since the menu is the same for all users, changing it in runtime for the state of single user will not work.

If you are building a custom module, our recommendation is that you add your menu items in the Init() method of your module. This will ensure that it will only be execute once in the application lifecycle.

Creating Menu Items

The MenuItem class has the following properties that you should set when adding a new item to the menu.

InternalId

As the menu is ordered into sections, at least the topmost level of items should have an Internal Id so that it's easy to access them when adding child items.

Name

This is the display name that will printed out in the menu when it is folded out.

Controller

The controller that generated link should point to. As the topmost level of items are only used as sections, this property is not needed for these items.

Action

The action that generated link should point to. As the topmost level of items are only used as sections, this property is not needed for these items.

Css

The css class that will be added to the icon for the menu item. The manager interface uses the font icons from Font Awesome, so any of the icons there will work.

Policy

If you want to restrict the menu item depending on the claims of the currently logged in user. Please note that each item can only have one policy, a policy can however be a set of several claims.

Adding Menu Items

Adding a Menu Section

The following code will add a new section below the Settings section.

using Piranha.Manager;

Menu.Items.Insert(2, new Menu.MenuItem
{
InternalId = "MyModule",
Name = "My Module",
Css = "fas fa-fish"
}

Adding a Menu Item

The following code will add a menu item under our new group.

using Piranha.Manager;

Menu.Items["MyModule"].Items.Add(new Menu.MenuItem
{
InternalId = "FirstFunction",
Name = "First Function",
Controller = "MyModule",
Action = "FirstAction",
Css = "fas fa-brain",
Policy = "MyFirstFunction"
}