Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 713 posts 954 karma points
    Nov 29, 2012 @ 01:25
    Tom
    0

    GetChildrenAsList in 4.10

    Just wondering how I'd do this is 4.10.. GetChildrenAsList has moved.. any chance we'll get updated API docs any time?

    At the moment I'm using reflector and it's slow going!

  • Tom 713 posts 954 karma points
    Nov 29, 2012 @ 01:29
    Tom
    0

    I basically want to convert this navigation snippet into a partial:

     var root = @Model;

        var menuItems = ((List<DynamicNode>)root.Children.Items).Where(dn => dn.Visible);

      var selectedPaths = new List<string>();

        <nav role="navigation" class="clearfix">

            <ul class="nav main-menu">

                @{

                    var homeSelected = @Model.Level == 1 ? " active" : ""; 

                    int menuCount = 0;

                }

                

            @foreach (var item in menuItems)

            {

                var isLast = menuCount == (menuItems.Count() - 1);

          var isFirst = menuCount == 0;

                var itemClass = isLast ? "last" : "";

                

                if((@Model.Level == 1 && isFirst) || (Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0))

          {

            itemClass = !string.IsNullOrEmpty(itemClass) ? itemClass + " active" : "active";    

          }

     

                if(isFirst)

          {

            itemClass = !string.IsNullOrEmpty(itemClass) ? itemClass + " first" : "first";    

          }

                

                var subItems = ((List<DynamicNode>)item.GetChildrenAsList.Items).Where(dn => dn.NodeTypeAlias != "Newspage" && dn.Visible).ToList();

                var currentPagePath = ((string[])Model.Path.Split(',')).ToList();

                

                if (subItems.Count() > 0)

                {

                    itemClass = !string.IsNullOrEmpty(itemClass) ? itemClass + " dropdown" : "dropdown";

                    <[email protected](!string.IsNullOrEmpty(itemClass) ? string.Format(" class=\"{0}\"", @itemClass) : "")>

                    <a href="@item.Url" class="dropdown-toggle" data-toggle="dropdown">@item.Name&nbsp;<b class="caret"></b></a>

                    <ul class="dropdown-menu">

                    @foreach (var subItem in subItems)

                    {

                      @RenderNavigationSubItem(subItem, currentPagePath);

                    }

                    </ul>

                    </li>

                }

                else

                {

                    bool itemIsExternalLink = item.NodeTypeAlias == "externalLink";

                    string linkUrl = itemIsExternalLink  ? item.GetPropertyValue("externalSiteUrl") : item.Url;

                    <[email protected](!string.IsNullOrEmpty(itemClass) ? string.Format(" class=\"{0}\"", @itemClass) : "")><a href="@linkUrl"@Html.Raw(itemIsExternalLink ? "rel=\"external\"" : "")>@item.Name</a></li>

                }

                menuCount = menuCount + 1;

            }

            </ul>

        </nav>

Please Sign in or register to post replies

Write your reply to:

Draft