How to get content from parent node to display in child nodes?
I have a navigation menu in a parent node. I need that menu to propagate down to all the child nodes. This should be much like the navigation of the root directory, where all the pages inside the root display the same navigation bar.
Here is what I have currently:
//Root Navigation
var primaryNav = site.Children.Where(x => x.DocumentTypeAlias == "primaryNavigationContainer").FirstOrDefault();
var navItemCollection = primaryNav?.Children.Where(x => x.DocumentTypeAlias == "primaryNavigationItem").ToList();
var ancestors = Model.Content.Ancestors().Where("Visible").OrderBy(x => x.Level);
//Navigation Inside Directory
var content = Model.Content;
var subNav = content.Children.Where(x => x.DocumentTypeAlias == "sectionNavigationContainer").FirstOrDefault();
var subNavItemCollection = subNav?.Children.Where(x => x.DocumentTypeAlias == "sectionNavItem").ToList();
//Get the URL for the current page
var url = HttpContext.Current.Request.Url.AbsolutePath;
bool hasSubNav = false;
//If URL to the page contains a specific string
if(url.ToString().ToUpper().Contains("StringSpecifier")){
primaryNav = subNav; //Replace the primary navigation with the section sub navigation
navItemCollection = subNavItemCollection; //Replace the primary collection with the section sub navigation collection
hasSubNav = true; //Set hasSubNav property
}
This displays fine in the Directory node, but it does not propagate to the pages inside the directory node.
Can anyone help me with how to get the sub navigation to display for the pages inside the directory node?
If I understand correctly, childs of a Directory aren't shown when you navigate to a child of that directory.
This is the result of var content = Model.Content.
You could perhaps do it like the following:
var content = Model.Content.AncestorOrSelf<Directory>();
This is written out of my head as I don't have a V7 running, but something similar like this should exist I ebelieve. It would get the current content, and if thats not of type Directory, would look upwards in the tree untill it finds one such type.
How to get content from parent node to display in child nodes?
I have a navigation menu in a parent node. I need that menu to propagate down to all the child nodes. This should be much like the navigation of the root directory, where all the pages inside the root display the same navigation bar.
Here is what I have currently:
This displays fine in the Directory node, but it does not propagate to the pages inside the directory node.
Can anyone help me with how to get the sub navigation to display for the pages inside the directory node?
If I understand correctly, childs of a Directory aren't shown when you navigate to a child of that directory.
This is the result of
var content = Model.Content
.You could perhaps do it like the following:
var content = Model.Content.AncestorOrSelf<Directory>();
This is written out of my head as I don't have a V7 running, but something similar like this should exist I ebelieve. It would get the current content, and if thats not of type Directory, would look upwards in the tree untill it finds one such type.
The read-only children property returns a live HTMLCollection which contains all of the child elements of the element upon which it was called.
Element.children includes only element nodes. To get all child nodes, including non-element nodes like text and comment nodes, use Node.childNodes.
epayitonline
I stumbled across what I was looking for.
Thank you Ambert and Korey. Your responses led me in the right direction.
is working on a reply...