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
Hi,
I cant seem to get my homepage to show up in my navigation menu.
Here is my code...........
@inherits umbraco.MacroEngines.DynamicNodeContext @{ var homePage = @Model.AncestorOrSelf(1); if (homePage != null) { <ul id="navigation"> @foreach (var item in homePage.Children.Where("Visible")) { if (Convert.ToInt32(item.GetProperty("showInHeaderNavigation").Value) > 0) { var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : ""; <li><a @Html.Raw(selected) href="@item.Url">@item.Name</a> </li> } } </ul> } }
Any help is appreciated
Thanks
Hi Joseph,
Just add your home page in manually before looping through the children;
@inherits umbraco.MacroEngines.DynamicNodeContext@{ var homePage =@Model.AncestorOrSelf(1); if(homePage !=null) { <ul id="navigation"> <li><a href="homePage.Url">@homePage.Name</a></li> @foreach(var item in homePage.Children.Where("Visible")) { if(Convert.ToInt32(item.GetProperty("showInHeaderNavigation").Value)>0) { var selected =Array.IndexOf(Model.Path.Split(','), item.Id.ToString())>=0?" class=\"selected\"":""; <li><a @Html.Raw(selected) href="@item.Url">@item.Name</a> </li> } } </ul> }}
Hope this helps,
Tony
Thanks for your help tony
I modified it so that it also sets the class if selected
@inherits umbraco.MacroEngines.DynamicNodeContext @using umbraco.MacroEngines; @{ var homePage = @Model.AncestorOrSelf(1); if (homePage != null) { <ul id="navigation"> @{ var homepageSelected = Model.Id == homePage.Id ? " class=\"selected\"" : ""; <li><a @Html.Raw(homepageSelected) href="@homePage.Url">@homePage.Name</a> </li> } @foreach (var item in homePage.Children.Where("Visible")) { if (Convert.ToInt32(item.GetProperty("showInHeaderNavigation").Value) > 0) { var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : ""; <li><a @Html.Raw(selected) href="@item.Url">@item.Name</a> </li> } } </ul> } }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Show home page in navigation
Hi,
I cant seem to get my homepage to show up in my navigation menu.
Here is my code...........
Any help is appreciated
Thanks
Hi Joseph,
Just add your home page in manually before looping through the children;
Hope this helps,
Tony
Thanks for your help tony
I modified it so that it also sets the class if selected
is working on a reply...