I'm trying to create a razor menu in umbraco with a razor macro. I followed the umbraco tutorial about creating a razor menu:
It works for my first three pages but then I want to add another one but the page doesn't show up in my menu. I have the following structure for my pages:
Start, calendar and Foto's do show up in my menu, but the news page doesn't. Is this structure correct or do I have to create a 'Home' page and place all my pages under that?
This is my razor macro code:
@inherits umbraco.MacroEngines.DynamicNodeContext
<nav>
<ul>
@{ var homeNode = Model.AncestorOrSelf("Home"); }
<li><a href="@homeNode.Url" class="@Library.If(homeNode.Id == Model.Id, "selected", "")">@homeNode.Name</a></li>
@foreach (var page in homeNode.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.Children.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>