如果它不包含值,我想隐藏我的侧导航的页眉和页脚。
@inherits UmbracoTemplatePage
<div id="LeftMenuHolder"> @*<----Not show/include these if list is empty*@
<span class="Head-Round-Red"> @*<----Not show/include these if list is empty*@
<span>@CurrentPage.Name</span> @*<----Not show/include these if list is empty*@
</span>@*<----Not show these if list is empty*@
<ul>
@if (CurrentPage.Parent.DocumentTypeAlias == "Home")
{
foreach (var item in CurrentPage.Children.Where("Visible"))
{
<li>
<a href="@item.Url">
<span>@item.Name</span>
</a>
</li>
}
}
else
{
foreach (var sibling in CurrentPage.Parent.Children)
{
<li>
<a href="@sibling.Url">
<span>@sibling.Name</span>
</a>
</li>
}
}
</ul>
<span class="BoxBot"> @*<----Not show/include these if list is empty*@
<span></span> @*<----Not show/include these if list is empty*@
</span> @*<----Not show/include these if list is empty*@
</div>
我确信这可以通过if语句解决,但我不太确定。
答案 0 :(得分:2)
您可以执行以下操作来检索兄弟节点,然后检查列表是否为空:
IPublishedContent parentNode = Umbraco.AssignedContentItem.Parent;
IEnumerable<IPublishedContent> siblingNodes = Umbraco.
AssignedContentItem.
Parent.
Children.
Where(x => !x.Name.Equals(Umbraco.AssignedContentItem.Name) &&
((bool)x.GetProperty("UmbracoNaviHide") == false);
对于您的实施,请尝试使用已初始化的属性进行此类操作(如果您在页面中没有UmbracoNaviHide
,请将其从Linq
语句中删除)并在此处删除此条件想要显示当前页面项:Where(x => !x.Name.Equals(Umbraco.AssignedContentItem.Name)
@inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
@{
IPublishedContent parentNode = Umbraco.AssignedContentItem.Parent;
IEnumerable<IPublishedContent> siblingNodes = Umbraco.
AssignedContentItem.
Parent.
Children.
Where(x => !x.Name.Equals(Umbraco.AssignedContentItem.Name) &&
((bool)x.GetProperty("UmbracoNaviHide") == false);
}
@if(siblingNodes.Any())
{
<div id="LeftMenuHolder"> @*<----Not show/include these if list is empty*@
<span class="Head-Round-Red"> @*<----Not show/include these if list is empty*@
<span>@CurrentPage.Name</span> @*<----Not show/include these if list is empty*@
</span> @*<----Not show these if list is empty*@
}
<ul>
@if (CurrentPage.Parent.DocumentTypeAlias == "Home")
{
foreach (var item in CurrentPage.Children.Where("Visible"))
{
<li>
<a href="@item.Url">
<span>@item.Name</span>
</a>
</li>
}
}
else
{
foreach (var sibling in CurrentPage.Parent.Children)
{
<li>
<a href="@sibling.Url">
<span>@sibling.Name</span>
</a>
</li>
}
}
</ul>
@if(siblingNodes.Any())
{
<span class="BoxBot"> @*<----Not show/include these if list is empty*@
<span></span> @*<----Not show/include these if list is empty*@
</span> @*<----Not show/include these if list is empty*@
}
</div>
此外,Umbraco
变量可从UmbracoViewPage
获得,因此您必须将继承模型更改为以下内容:@inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
。