我正在尝试在 Umbraco 安装中的顶部和子菜单项上设置“当前”类。
顶部菜单就像:
Home Products About Contact
现在,当我单击假设产品时,我将类名设置为“当前”。同时它会加载一个像这样的子菜单:
Jeans
Sweeters
T-shirts
- Red
- Green
- Blue
当我点击让我们说 Sweeters 时,我不想让产品链接和 sweeters 链接拥有当前类。我怎样才能做到这一点?
顶部菜单代码
@{
<ul class="topnavigation">
@foreach (var c in Model.AncestorOrSelf(2).Children.Where("umbracoNaviHide!=true"))
{
<li class="@(Model.Id == c.Id ? "current" : "")"><a href="@c.Url">@c.Name</a></li>
}
</ul>
}
子菜单代码
@{
<ul>
@foreach (var page in @Model.AncestorOrSelf(3).Children)
{
string style = string.Empty;
if (Model.Id == page.Id) { style = "class=current"; }
<li @style><a href="@page.Url" @Html.Raw(style)>@page.Name</a></li>
if (page.Childen != null && page.Children.Count() > 0 && Model.AncestorsOrSelf().Where("Id == @0", page.Id).Count() > 0)
{
<ul>
@foreach (dynamic secondPage in page.Children.Where("!umbracoNaviHide"))
{
string style1 = string.Empty;
if (Model.Id == secondPage.Id) { style1 = "class=current"; }
<li @style1>
- <a href="@secondPage.Url">@secondPage.Name</a>
</li>
}
</ul>
}
}
</ul>
}