Skip to content

ARCHIVED

!注意“归档”

This chapter has not been updated for the current version of Orchard, and has been ARCHIVED.

An Admin menu is a menu which only appears in the admin website. There are 2 levels of admin menus available on the side menu and the second level is by default collapsed. Adding a third level is possible, but this will only be displayed as a tabbed navigation on top of the pages.

管理员菜单是仅显示在管理员网站中的菜单。侧边菜单上有两个级别的管理菜单,默认情况下折叠第二级。可以添加第三级,但这只会在页面顶部显示为选项卡式导航。

Adding an Orchard admin module starts with a class implementing the INavigationProvider:

添加Orchard管理模块从实现INavigationProvider的类开始:

public interface INavigationProvider : IDependency {

    string MenuName { get; }

    void GetNavigation(NavigationBuilder builder);

}

In here the MenuName property should always return the value "admin", signalling to Orchard that this is an admin menu instead of a normal menu.

在这里,MenuName属性应该始终返回值“admin”,向Orchard发信号通知这是一个管理菜单而不是普通菜单。

Adding a single level

添加单个级别

using Orchard.UI.Navigation;

namespace Orchard.Webshop

{

public class AdminMenu : INavigationProvider

{

    public string MenuName {

        get { return "admin"; }

    }



    public AdminMenu() {

        T = NullLocalizer.Instance;

    }



<font color=#0099ff size=4 face="黑体"></font>


    private Localizer T { get; set; }

    public void GetNavigation(NavigationBuilder builder) {

        builder



            // Image set

            .AddImageSet("webshop")

            // "Webshop"

            .Add(item => item

                .Caption(T("Webshop"))

                .Position("2")

                .Action("Index", "CustomerAdmin", new { area = "Orchard.Webshop" })

            );

    }

}

}

This will result in a single item being added to the admin menu. The AddImageSet lets you create an image (in a set of related css files) to display in the navigation menu. Position is the order in which the menu's are displayed.

这将导致将单个项目添加到管理菜单。 AddImageSet允许您创建要在导航菜单中显示的图像(在一组相关的css文件中)。位置是菜单显示的顺序。

Adding 2nd level menu items

添加第二级菜单项

By adding more .Add statements nested in the parent menu, we can generate a second menu level. With the .LinkToFirstChild we don't need an action anymore in the parent item, we'll use the first one from the first child.

通过添加嵌套在父菜单中的更多.Add语句,我们可以生成第二个菜单级别。使用.LinkToFirstChild,我们不再需要在父项中执行操作,我们将使用第一个子项中的第一个操作。

    public void GetNavigation(NavigationBuilder builder) {

        builder



            // Image set

            .AddImageSet("webshop")

            // "Webshop"

            .Add(item => item

                .Caption(T("Webshop"))

                .Position("2")

                .LinkToFirstChild(true)

                    .Add(localItem => localItem

                        .Caption(T("Customers"))

                        .Action("Index", "CustomerAdmin", new { area = "Orchard.Webshop" })

                    )

                     .Add(localItem => localItem

                        .Caption(T("Orders"))

                        .Action("Index", "OrdersAdmin", new { area = "Orchard.Webshop"  })

                    )

            );

    }

Adding multiple tabs to a page (3rd level)

向页面添加多个选项卡(第3级)

For this we can use the .LocalNav() method.

为此,我们可以使用.LocalNav()方法。

public void GetNavigation(NavigationBuilder builder) {

  builder.AddImageSet("webshop")

    .Add(T("Customers"), "7", menu => menu.Action(...})

      .Add(T("Details"), "0", item => item.Action(...}).LocalNav())

      .Add(T("History"), "1", item => item.Action(...).LocalNav())

      .Add(T("Contact"), "2", item => item.Action(...).LocalNav()));

}

Be careful, if the Current displayed url is not part of the LocalNav pages, no tabs are displayed. You first have to navigate to one of the pages for the LocalNav to display.

注意,如果当前显示的URL不是LocalNav页面的一部分,则不显示任何选项卡。首先必须导航到LocalNav要显示的其中一个页面。