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
I'm trying to build a very complex menu and really need some help.
I've put together some examples of how the sub nav needs to work in the following document:
http://dl.dropbox.com/u/528350/kws-sub-nav.docx
I've also got the nav kind of working here:
http://31.222.141.203/level-2.aspx
Notice that all the branches open as you step down the navigation tree. What does not happen is essentially:
I only want to display the chiildren and parents of the currently selected node. Not all nodes.
The code I have so far is:
@inherits umbraco.MacroEngines.DynamicNodeContext @functions{ int level_3 = 1; string open_level_3 = ""; string open_level_4 = "";}@{ int level_2_node_id = 0; foreach (var level in @Model.Ancestors().Where("Visible").Where("Level == 2")) { <h2><a href="@level.Url">@level.Name</a></h2> level_2_node_id = @level.Id; } if (@Model.Level == 2) { <h2><a href="@Model.Url">@Model.Name</a></h2> level_2_node_id = @Model.Id; } }@helper traverse(dynamic node){ var items = node.Children.Where("Visible").Where("Level <= 99").Where("NodeTypeAlias != \"contact-us\"").Where("NodeTypeAlias != \"HomepageSlide\"").Where("NodeTypeAlias != \"search\"").Where("NodeTypeAlias != \"GalleryMediaItem\"").Where("NodeTypeAlias != \"InteriorSlide\"").Where("NodeTypeAlias != \"FocusedLandingSlide\""); foreach (var item in items) { if (@Model.Name == @node.Name) { open_level_3 = "level3"; } } if (items.Count() > 0 && @Model.Level >= @node.Level) { <ul class="nav clearfix" id="level_@(node.Level + 1)"> @foreach (var item in items) { <li @if (@Model.Url == @item.Url){@Html.Raw("class=\"selected\"");}><a href="@item.Url">@item.Name</a> @traverse(item) </li> } </ul> } }<div class="results"> @traverse(@Model.NodeById(@level_2_node_id))</div>
Hi Dominic,
You could try using the IsAncestorOrSelf helper to determine if you should render the subpages or not - so basically if the current page in the loop is an ancestor of the current page, then render the submenu.
Maybe this might do the trick:
@if (item.IsAncestorOrSelf(Model)) { @traverse(item)}
Check the Razor Cheat Sheet for other helpers :)
-Tom
You have made me a very happy man! I knew I was close, I just couldn't get my head around the last part.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor sub-nav
I'm trying to build a very complex menu and really need some help.
I've put together some examples of how the sub nav needs to work in the following document:
http://dl.dropbox.com/u/528350/kws-sub-nav.docx
I've also got the nav kind of working here:
http://31.222.141.203/level-2.aspx
Notice that all the branches open as you step down the navigation tree. What does not happen is essentially:
I only want to display the chiildren and parents of the currently selected node. Not all nodes.
The code I have so far is:
Hi Dominic,
You could try using the IsAncestorOrSelf helper to determine if you should render the subpages or not - so basically if the current page in the loop is an ancestor of the current page, then render the submenu.
Maybe this might do the trick:
Check the Razor Cheat Sheet for other helpers :)
-Tom
You have made me a very happy man! I knew I was close, I just couldn't get my head around the last part.
is working on a reply...