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 found the code below on another topic to do a 2nd level navigation, but its giving me a really odd error:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\d4850de4\c311c2c8\AppWeb635108881622787274_mainnavnew.cshtml.70df5e80.g7kslbm9.0.cs(212): error CS1513: } expected
Does anyone know if there is something wrong with the script or has something gone wrong elsewhere?
@inherits umbraco.MacroEngines.DynamicNodeContext @{ var startLevel = 1; var finishLevel = 2; var parent = @Model.AncestorOrSelf(startLevel); if (parent != null) { @ulMenu(parent, startLevel, finishLevel) ; } } @helper ulMenu(dynamic parent, int startLevel, int finishLevel){ <ul @Html.Raw(ulClass)> @foreach (var node in parent.Children.Where("Visible")) { <li> <a href="@node.Url">@node.Name</a> @if (@node.Level <= finishLevel) { @ulMenu(node, startLevel, finishLevel); } </li> } </ul> }
Hi Adam,
There are a few extra @ that need to be removed, in Umbraco v4 they were forgiven but in v6 they are not.
Try
@inherits umbraco.MacroEngines.DynamicNodeContext @{ var startLevel = 1; var finishLevel = 2; var parent = Model.AncestorOrSelf(startLevel); if (parent != null) { @ulMenu(parent, startLevel, finishLevel) } } @helper ulMenu(dynamic parent, int startLevel, int finishLevel){ <ul @Html.Raw(ulClass)> @foreach (var node in parent.Children.Where("Visible")) { <li> <a href="@node.Url">@node.Name</a> @if (node.Level <= finishLevel) { @ulMenu(node, startLevel, finishLevel) } </li> } </ul> }
It looks like you are also missing a declaration of the ulClass, maybe it should be like:
@inherits umbraco.MacroEngines.DynamicNodeContext @{ var startLevel = 1; var finishLevel = 2; var parent = Model.AncestorOrSelf(startLevel); if (parent != null) { @ulMenu(parent, startLevel, finishLevel, "") } } @helper ulMenu(dynamic parent, int startLevel, int finishLevel, string ulClass){ <ul @Html.Raw(ulClass)> @foreach (var node in parent.Children.Where("Visible")) { <li> <a href="@node.Url">@node.Name</a> @if (node.Level <= finishLevel) { @ulMenu(node, startLevel, finishLevel, "") } </li> } </ul> }
Thanks a lot for the reply the above is rendering all the links in an li each which wouldnt work for a dropdown navigation
So I've got this which renders out the dropdown correctly but its rendering every single page
Is there a way so the main navigaiton isnt popuplated unless a true/false option is checked i.e. show in navigation?
@inherits umbraco.MacroEngines.DynamicNodeContext <ul class="myMenu"> <li><a href="/">Home</a> </li> @foreach (var page in @Model.AncestorOrSelf(1).Children) { string style = ""; if (Model.Id == page.Id) { style = "class=\"current\""; } <li> <a href="@page.Url" @Html.Raw(style)>@page.Name</a> @if (page.Childen != null && page.Children.Count() > 0) { <ul> @foreach (dynamic secondPage in page.Children) { <li> <a href="@secondPage.Url">@secondPage.Name</a> </li> } </ul> } </li> } </ul>
Yes, but normally this is done in reverse, add a property called "Hide in navigation" with the alias of "umbracoNaviHide" and tick the pages you want to hide, then
@foreach (var page in @Model.AncestorOrSelf(1).Children.Where("Visible"))
Brilliant thanks!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
2nd level navigation
I found the code below on another topic to do a 2nd level navigation, but its giving me a really odd error:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\d4850de4\c311c2c8\AppWeb635108881622787274_mainnavnew.cshtml.70df5e80.g7kslbm9.0.cs(212): error CS1513: } expected
Does anyone know if there is something wrong with the script or has something gone wrong elsewhere?
Hi Adam,
There are a few extra @ that need to be removed, in Umbraco v4 they were forgiven but in v6 they are not.
Try
It looks like you are also missing a declaration of the ulClass, maybe it should be like:
Thanks a lot for the reply the above is rendering all the links in an li each which wouldnt work for a dropdown navigation
So I've got this which renders out the dropdown correctly but its rendering every single page
Is there a way so the main navigaiton isnt popuplated unless a true/false option is checked i.e. show in navigation?
Yes, but normally this is done in reverse, add a property called "Hide in navigation" with the alias of "umbracoNaviHide" and tick the pages you want to hide, then
Brilliant thanks!
is working on a reply...