This project is read-only.

Creating Multilayered Menu

Topics: Themes
Feb 23, 2014 at 2:38 PM

My department had requested me to do a multilayer sub menu. The main problem is i'm new to blogengine and its really my learning curve and my new experience.

I already read site.master line in the standard theme and as far as I understand, the loop looks like only allow 2 layer of sub menu (Menu -> sub-menu) and I try to make Menu -> subLayer1 -> subLayer2 -> sublayer3
<%foreach (BlogEngine.Core.Page parentPage in BlogEngine.Core.Page.Pages.Where(p => !p.HasParentPage && p.IsPublished && p.ShowInList)) 
{ %><li class="Left Page-Link"><a href="<%=parentPage.RelativeLink %>" title="<%=parentPage.Title%>"><%=parentPage.Title%></a> 
  <%if (parentPage.HasChildPages) 
  { %> <ul class="Sub-Page-Links"> 
    <%foreach (BlogEngine.Core.Page childPage in BlogEngine.Core.Page.Pages.Where(p => p.Parent == parentPage.Id && p.IsPublished)) 
    { %> <li class="Left"><a href="<%=childPage.RelativeLink %>" title="<%=childPage.Title %>"><%=childPage.Title %></a> </li><% 
    } %> </ul><% 
  } %></li><% 
} %>
Can somebody explains to me the right code that I need to put as I really don't quite understand about the "if (parentPage.HasChildPages)" sentence in the foreach loop

Sorry as I'm really new about BE and there's a lot more to learn.

I'm using standard theme in BE2.8 to understand how BE works.

Thanks in advance
Feb 23, 2014 at 10:43 PM
In admin you can set any page as parent to another page, so you can have parent -> child -> grandchild etc going as deep as you like. The line "if (parentPage.HasChildPages)" simply checks if a page has any child pages. The PageMenu.cs control in the controls folder of App_Code will give you a multilayer menu. You could replace the default menu code in the Standard theme site.master with something like this.
<div class="navbar-collapse collapse">
    <blog:PageMenu ID="PM" runat="server" />
However, to make it behave the same as the Standard theme menu, you would need to alter the source code adding classes to UL and list items to match the classes in the Standard theme's default menu. Look at BlogEngine.Core/Web/Controls/PageMenu to see how this works and to determine exactly what needs changing to suit your needs.
Feb 24, 2014 at 8:38 AM
Edited Feb 24, 2014 at 8:49 AM
Thanks for the help

I've already set the parent for the pages that I want to make a Menu.
But only up to Parent -> Child that visible to the page. Wondering why the grandchild is not visible

I'll try again later.

Again, Thanks for the advice