Alloy.Helpers.HtmlHelpers.MenuList C# (CSharp) Метод

MenuList() публичный статический Метод

Returns an element for each child page of the rootLink using the itemTemplate.
Filter by access rights and publication status.
public static MenuList ( this helper, EPiServer.Core.ContentReference rootLink, HelperResult>.Func itemTemplate = null, bool includeRoot = false, bool requireVisibleInMenu = true, bool requirePageTemplate = true ) : IHtmlString
helper this The html helper in whose context the list should be created
rootLink EPiServer.Core.ContentReference A reference to the root whose children should be listed
itemTemplate HelperResult>.Func A template for each page which will be used to produce the return value. Can be either a delegate or a Razor helper.
includeRoot bool Wether an element for the root page should be returned
requireVisibleInMenu bool Wether pages that do not have the "Display in navigation" checkbox checked should be excluded
requirePageTemplate bool Wether page that do not have a template (i.e. container pages) should be excluded
Результат IHtmlString
        public static IHtmlString MenuList(
            this HtmlHelper helper, 
            ContentReference rootLink, 
            Func<MenuItem, HelperResult> itemTemplate = null, 
            bool includeRoot = false, 
            bool requireVisibleInMenu = true, 
            bool requirePageTemplate = true)
        {
            itemTemplate = itemTemplate ?? GetDefaultItemTemplate(helper);
            var currentContentLink = helper.ViewContext.RequestContext.GetContentLink();
            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();

            Func<IEnumerable<PageData>, IEnumerable<PageData>> filter =
                pages => pages.FilterForDisplay(requirePageTemplate, requireVisibleInMenu);

            var pagePath = contentLoader.GetAncestors(currentContentLink)
                .Reverse()
                .Select(x => x.ContentLink)
                .SkipWhile(x => !x.CompareToIgnoreWorkID(rootLink))
                .ToList();

            var menuItems = contentLoader.GetChildren<PageData>(rootLink)
                .FilterForDisplay(requirePageTemplate, requireVisibleInMenu)
                .Select(x => CreateMenuItem(x, currentContentLink, pagePath, contentLoader, filter))
                .ToList();

            if(includeRoot)
            {
                menuItems.Insert(0, CreateMenuItem(contentLoader.Get<PageData>(rootLink), currentContentLink, pagePath, contentLoader, filter));
            }

            var buffer = new StringBuilder();
            var writer = new StringWriter(buffer);
            foreach (var menuItem in menuItems)
            {
                itemTemplate(menuItem).WriteTo(writer);
            }

            return new MvcHtmlString(buffer.ToString());
        }