Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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!
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 <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;
</nav>
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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!
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 <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>
is working on a reply...