Problem with Menu - only listing Decendants at this level and not decendants of a diffent node at the same level
I am having a total brain block here.
The goal is to build a subnavigation menu where all nodes of levels 2 to 4 are visible, but if the user is on a submenu that has subnodes at level 5, or 6 then those items should show. But not items of level 5 and 6 for other nodes of level 2,3,or 4.
However what i seem to be stuck on is getting all items of a level or none below the level of 4. I have been trying to work with .IsDescendant, but think it is probably wrong for this.. or I am just not using it correctly..
Any help is greatly appreciated.
Here is the code (currently it is all of a the level of @Model.Level)
Seems to work for me - if I'm on a branch of the tree that is four or less levels deep, the navigation lists all nodes at levels 2-4. If I'm on a branch with more than four levels, it lists levels 5 and 6, but only for that branch. I'm checking that a node has descendants at level 5, the node is a descendant of the current node, and then traversing children up to level 5 (to display level 6 nodes). If there are no descendants at level five, then we traverse as far as level 3 (to get the level four nodes)
Should at least be a step in the right direction. Hope that helps.
Nathan, thanks. I will try that tonight when i get home. It looks like you have probably hit on my soultion for me. Looking at your code also makes me think i may have had the test for descendant on the wrong side of the || - classic logic error !
Problem with Menu - only listing Decendants at this level and not decendants of a diffent node at the same level
I am having a total brain block here.
The goal is to build a subnavigation menu where all nodes of levels 2 to 4 are visible, but if the user is on a submenu that has subnodes at level 5, or 6 then those items should show. But not items of level 5 and 6 for other nodes of level 2,3,or 4.
However what i seem to be stuck on is getting all items of a level or none below the level of 4. I have been trying to work with .IsDescendant, but think it is probably wrong for this.. or I am just not using it correctly..
Any help is greatly appreciated.
Here is the code (currently it is all of a the level of @Model.Level)
@using umbraco.MacroEngines;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
const int startLevel = 2;
var finishLevel [email protected];
var parent = @CurrentModel.AncestorOrSelf(startLevel);
if (parent != null)
{
@traverse(parent,startLevel,finishLevel) ;
}
}
@helper traverse(dynamic parent,int startLevel,int finishLevel)
{ <ul> @foreach (var node in parent.Children.Where("Visible"))
{
<li>
<a href="@node.Url">@node.Name</a>
@if (@node.Level <= finishLevel||(@node.DescendantsOrSelf))
{
@traverse(node,startLevel,finishLevel);
}
</li>
}
</ul>
}
Hi Rob,
What you could do is try to display all nodes from level 2 with a docTypeName. Something like
//fuji
Hi Rob,
I'd try something like this (I'm assuming you want to show all nodes at levels 2-4, not just relative to the current node) -
Seems to work for me - if I'm on a branch of the tree that is four or less levels deep, the navigation lists all nodes at levels 2-4. If I'm on a branch with more than four levels, it lists levels 5 and 6, but only for that branch. I'm checking that a node has descendants at level 5, the node is a descendant of the current node, and then traversing children up to level 5 (to display level 6 nodes). If there are no descendants at level five, then we traverse as far as level 3 (to get the level four nodes)
Should at least be a step in the right direction. Hope that helps.
cheers
Nathan
Nathan, thanks. I will try that tonight when i get home. It looks like you have probably hit on my soultion for me. Looking at your code also makes me think i may have had the test for descendant on the wrong side of the || - classic logic error !
THANKS!!!
Rob
is working on a reply...