Hi, I'm trying to figure out why the bollowing snippet isn't behaving as expected. It should iterate through all content and child content, find any content that is marked "VisibleInMenu" and then add them to a list.
Func, IEnumerable> filter =
pages => pages.FilterForDisplay(requirePageTemplate, requireVisibleInMenu);
foreach (var menuItem in menuItems.ToList())
bool children = false;
bool.TryParse(menuItem.HasChildren.Value.ToString(), out children);
var childItems = contentLoader.GetChildren(menuItem.Page.ContentLink)
.Select(x => CreateMenuItem(x, currentContentLink, pagePath, contentLoader, filter))
childItems = recursiveMenu(childItems, pagePath, contentLoader, currentContentLink, requirePageTemplate, requireVisibleInMenu);
Any help would be much appreciated. Thanks.
Use Get descendants instead? Then you can filter that on access rights, visible in menu etc...?
Can't see anything obviously wrong. Do you have the contents of that recursive function? What does it actually return? Errors?
I actually figured out what I've been doing wrong. I'm not precisely sure how to fix it but my logic in this snippet is working perfectly. It only gets added to the menu if its parent is part of the menu structure. If the parent is not part of the structure, neither is the child. In retrospect the problem was with my logic, not with the code itself.