Good day! working on Umbraco and struggling to create dynamic menu in Umbraco. The menu li's should be called using menuName.

It works for first loop (static menu called item.menuName), but does not work in second - node.menuName. node.Name is works, but .menuName does not. Why?

Thank you!

    var homePage = CurrentPage.AncestorsOrSelf(1).First();
    var menuItems = homePage.Children.Where("UmbracoNaviHide == false");

<ul class="menu">

    @foreach (var item in menuItems)
    {
        var childrenItems = item.Children.Where("UmbracoNaviHide == false");
        <li class="@(CurrentPage.Id == item.Id ? "sel" : null)">
            <a href="@item.Url"><h4>@item.menuName</h4></a>
            @createSubmenu(childrenItems, item.Id)
        </li>
    }
</ul>

@helper createSubmenu(IEnumerable<IPublishedContent> nodes, int? parentId) {
    if (nodes.Count() > 0){
        <ul>
        @foreach (var node in nodes)
        {
            var childrenItems = node.Children.Where("UmbracoNaviHide == false");
            <li class="@(CurrentPage.Id == node.Id ? "sel" : null)">
                <a href="@node.Url"><h5>@node.menuName</h5></a>
                @createSubmenu(childrenItems, node.Id)
            </li>
        }
        </ul>
    }
}

Related posts

Recent Viewed