我正在尝试使用剃刀宏在 umbraco 中创建剃刀菜单。我按照关于创建剃刀菜单的 umbraco 教程进行操作:
它适用于我的前三页,但后来我想添加另一页,但该页面未显示在我的菜单中。我的页面具有以下结构:
开始、日历和照片确实出现在我的菜单中,但新闻页面没有。这种结构是否正确,还是我必须创建一个“主页”页面并将我的所有页面放在其下?
这是我的剃刀宏代码:
@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>