Navigation with sub navigation, only show current node's subnav or current Nodes parent subnav
I have my navigation buile and have a question about navigation with subnav and showing only the current nodes subnav IF the current node is selected AND if the current node is a subpage of the node with the subnav. Currently my navigation is showing ALL subnav if I am on a node with sub navigation in it. I only need to show the current nodes subnav or if it current node is a child of the main nav node with the subnav then I need to also show its siblings nav.
This is what I have so far. There is a small thing I am missing and I can't figure out what it is.
Navigation with sub navigation, only show current node's subnav or current Nodes parent subnav
I have my navigation buile and have a question about navigation with subnav and showing only the current nodes subnav IF the current node is selected AND if the current node is a subpage of the node with the subnav. Currently my navigation is showing ALL subnav if I am on a node with sub navigation in it. I only need to show the current nodes subnav or if it current node is a child of the main nav node with the subnav then I need to also show its siblings nav.
This is what I have so far. There is a small thing I am missing and I can't figure out what it is.
<nav id="minisiteMenuBar"> <ul> @{var homeNode = @Model.AncestorOrSelf("MinisiteHomepage");} <li><a href="@homeNode.Url" class="@Library.If(homeNode.Id == Model.Id, "selected", "")">Home</a></li> @foreach (var page in homeNode.Children.Where("Visible")) { <li> <a href="@page.Url" class="@Library.If(page.Id == Model.Id, "selected", "")">@page.Name</a> @if(@Model.NodeTypeAlias == "MinisitePage" && @Model.Children.Where("Visible").Count() > 0){ if(@page.Children.Where("Visible").Count() > 0) { <ul> @foreach(var childPage in page.Children.Where("Visible && NodeTypeAlias == \"MinisitePage\"")) { <li><a href="@childPage.Url" class="@Library.If(childPage.Id == Model.Id, "selected", "")">@childPage.Name</a></li> } </ul> } } else if(@Model.Parent.NodeTypeAlias == "MinisitePage"){ <ul> @foreach(var childPage in page.Children.Where("Visible && NodeTypeAlias == \"MinisitePage\"")) { <li><a href="@childPage.Url" class="@Library.If(childPage.Id == Model.Id, "selected", "")">@childPage.Name</a></li> } </ul> } else{} </li> } </ul> </nav> }I found my issue.
For my else if statement it should look like this
else if(page.Id == Model.Parent.Id){ <ul> @foreach(var childPage in @Model.Parent.Children.Where("Visible && NodeTypeAlias == \"MinisitePage\"")){ <li><a href="@childPage.Url" class="@Library.If(childPage.Id == Model.Id, "subSelected", "")"> @childPage.Name</a></li> } </ul> }Hi Carlos,
Try this one instead.
Hope this helps,
/Dennis
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.