i am very much new in Umbraco CMS and started coding in it recently. My page structure is like this
And now I have written the code like this to generate the dynamic navigation based on the code I have found in Umbraco forums. But in output it is giving only the 'Home' as the link not other links.The reason is that I have written it like this { var homeNode = Model.AncestorOrSelf(1); } and it is only returning home page not other pages. i have tried using this also Model.AncestorOrSelf(). But it is giving same result.
<nav>
<ul>
@{ var homeNode = Model.AncestorOrSelf(1); }
<li><a href="@homeNode.Url" class="@Library.If(homeNode.Id == Model.Id, "selected", "")">@homeNode.Name</a></li>
@foreach (var page in Model.Children.Where("Visible"))
{
var isSelected = false;
if (Model.Id == page.Id || (Model.Parent != null && Model.Parent.Id == page.Id && Model.NodeTypeAlias != "Textpage"))
{
isSelected = true;
}
<li>
<a href="@page.Url" class="@Library.If(isSelected, "selected", "")">@page.Name</a>
<!-- If the page has child nodes (2nd level) that are visible and docTypeAlias is Textpage (textpages) -->
@if (page.Textpages.Where("Visible").Count() > 0)
{
<ul>
@foreach (var childPage in page.Children.Where("Visible"))
{
<li><a href="@childPage.Url" class="@Library.If(childPage.Id == Model.Id, "selected", "")">@childPage.Name</a></li>
}
</ul>
}
</li>
}
</ul>
</nav>
What will be the proper expression to traverse this.
Thanks and Regards
utpal