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
Hi Guys,
I kind of lost my way here. I need to display sub nodes when current node only has any child node.
Here is how i have it structured
Node 1Node 2 Node 3-- SubNode 1-- SubNode 2
So only when on Node 3 page content that i will display the subContent. Here is how my code looks like
@foreach(var c in pages.Where(x=>x.GetPropertyValue("umbracoNaviHide").ToString() !="1")){ <li><a href="@c.Url">@Html.Raw(altSubTitle)</a></li> if(CurrentModel.Children.Count() > 0){ @Model.Name } }
Weird i cant seem to remember how to achieve this here. Anyone please?
I'm not totally understanding what your doing but maybe something like:
if(pages.Id == CurrentModel.Id && CurrentModel.Children.Count() > 0){ @Model.Name } }
Hi Jeavon,
Basically i wanted to display the subNode only if am on the Node 3. So whenever i click on Node 3 i get the sub nodes.
I did try this but didnt worked
if(c.Id == Model.Id && c.ChildrenAsList.Where(x=>x.GetProperty("umbracoNaviHide").Value !="1" && x.NodeTypeAlias == "AddSubPage").Count() > 0){
}
Instead i managed doing it in css, only displaying the UL when on the current Node 3 or any sub node
if(c.ChildrenAsList.Where(x=>x.NodeTypeAlias == "DocType").Count() > 0){ <ul class="sub-navi @Library.If((c.IsAncestorOrSelf(Model)), "subNaviAct", "")"> @foreach(var page in c.ChildrenAsList.Where(x=>x.NodeTypeAlias == "docType")){ string active = (page.IsAncestorOrSelf(@Model)) ? "class=current" : ""; <li @active><a href="@page.Url">@page.Name</a></li> } </ul> }
Hi Fuji
Ok, so does Node 3 have a special doc type or should we check its Name?
Jeavon
No same all of them have the same docType but turns out it stopped working. I need to figure out something else. On a certain level it stopped
Ok, I need to get this straight :-)
Node structure:
Node 1 -- SubNode 1 -- SubNode 2 Node 2 -- SubNode 3 -- SubNode 4 Node 3 -- SubNode 5 -- SubNode 6
When rendering Node 3, SubNode 5 and SubNode 6, you want output like
Node 1 Node 2 Node 3 -- SubNode 5 -- SubNode 6
When rendering Node 2, SubNode 3 and SubNode 4, you want output like
Node 1 Node 2 -- SubNode 3 -- SubNode 4 Node 3
Have I got it right?
Hmmmm yes exactly,
Node 1 Node 2Node 3 - Active Displaying the sub Node 3-4-- Sub Node 1-- Sub Node 2Node 4
And when under Sub Node 1
Still displaying Node 1Node 2Node 3 -- -- Sub Node 1 Active-- Sub Node 2Node 4
And when under Node 1
Node 1 -- ActiveNode 2Node 3Node 4
Assuming you are stuck with DynamicNode rather the super fast IPublishedContent. how about something like this:
@{ var home = CurrentModel.AncestorOrSelf(1).Children; <ul> @foreach (var page in home) { var selectedItemState = page.DescendantsOrSelf().Any(x => x.Id == Current.Id); <li class="@(selectedItemState ? "active" : null)"> @page.Name @if (selectedItemState && page.Children.Any()) { <ul> @foreach (var childPage in page.Children) { var selectedChildItemState = childPage.DescendantsOrSelf().Any(x => x.Id == Current.Id); <li class="@(selectedChildItemState ? "active" : null)">@childPage.Name</li> } </ul> } </li> } </ul> }
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Displaying child node if currentNode has child
Hi Guys,
I kind of lost my way here. I need to display sub nodes when current node only has any child node.
Here is how i have it structured
Node 1
Node 2
Node 3
-- SubNode 1
-- SubNode 2
So only when on Node 3 page content that i will display the subContent. Here is how my code looks like
Weird i cant seem to remember how to achieve this here. Anyone please?
I'm not totally understanding what your doing but maybe something like:
Hi Jeavon,
Basically i wanted to display the subNode only if am on the Node 3. So whenever i click on Node 3 i get the sub nodes.
I did try this but didnt worked
if(c.Id == Model.Id && c.ChildrenAsList.Where(x=>x.GetProperty("umbracoNaviHide").Value !="1" && x.NodeTypeAlias == "AddSubPage").Count() > 0){
}
Instead i managed doing it in css, only displaying the UL when on the current Node 3 or any sub node
Hi Fuji
Ok, so does Node 3 have a special doc type or should we check its Name?
Jeavon
No same all of them have the same docType but turns out it stopped working. I need to figure out something else. On a certain level it stopped
Ok, I need to get this straight :-)
Node structure:
When rendering Node 3, SubNode 5 and SubNode 6, you want output like
When rendering Node 2, SubNode 3 and SubNode 4, you want output like
Have I got it right?
Hmmmm yes exactly,
And when under Sub Node 1
And when under Node 1
Assuming you are stuck with DynamicNode rather the super fast IPublishedContent. how about something like this:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.