Please note that version 9 is still in beta. For documentation on the latest stable release, please change to version 8.
Contribute to Docs Contribute to Docs

Menu

When adding new functionality to the manager you'll want to add items for your new page in the menu. The menu class 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 a 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.

If you are just adding menu items in your application we recommend that you do it in your Startup.cs after Piranha.App.Init() has been called.

Customizing the menu

Please note that empty menu sections will not be rendered. The same also applies for menu sections only containing items that the current user don't have access to.

Adding a Section

The following code will add a new section after the default Settings section.

using Piranha.Manager;

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

Adding an Item

The following code will add a menu item under our new group we create in the previous step.

using Piranha.Manager;

Menu.Items["MyModule"].Items.Add(new MenuItem
{
    InternalId = "MyCustomItem",
    Name = "My Custom Item",
    Route = "~/manager/mycustomitem",
    Css = "fas fa-brain",
    Policy = "MyCustomPolicy"
});

Menu Item Properties

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

InternalId
menuItem.InternalId = "MyCustomItem";

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
menuItem.Name = "My Custom Item";

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

Route

menuItem.Route = "~/manager/mycustomitem";

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

Css
menuItem.Css = "fas fa-fish";

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
menuItem.Policy = "MyCustomPolicy";

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.