I would like to hide my side navigation if contains no content. I'm sure this can be solved using "if Any something..." Im not quite sure. I would appriciate if you guys could help me out.
Here is my side navigation code.
@inherits UmbracoTemplatePage
<div id="LeftMenuHolder"> @*<----Not show these if list is empty*@
<span class="Head-Round-Red"> @*<----Not show these if list is empty*@
<span>@CurrentPage.Name</span> @*<----Not show 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 these if list is empty*@
<span></span> @*<----Not show these if list is empty*@
</span> @*<----Not show these if list is empty*@
</div>
@inherits UmbracoTemplatePage
@{
var navItems = CurrentPage.Parent.DocumentTypeAlias == "Home" ? CurrentPage.Children.Where("Visible").ToList() : CurrentPage.Parent.Children.ToList();
}
@if(navItems.Any())
{
<div id="LeftMenuHolder"> @*<----Not show these if list is empty*@
<span class="Head-Round-Red"> @*<----Not show these if list is empty*@
<span>@CurrentPage.Name</span> @*<----Not show these if list is empty*@
</span>@*<----Not show these if list is empty*@
<ul>
@foreach (var item in navItems)
{
<li>
<a href="@item.Url">
<span>@item.Name</span>
</a>
</li>
}
</ul>
<span class="BoxBot"> @*<----Not show these if list is empty*@
<span></span> @*<----Not show these if list is empty*@
</span> @*<----Not show these if list is empty*@
</div>
}
This has not been tested but I think it should work.
Hide navigation if empty
I would like to hide my side navigation if contains no content. I'm sure this can be solved using "if Any something..." Im not quite sure. I would appriciate if you guys could help me out.
Here is my side navigation code.
I think you can do it like this :
This has not been tested but I think it should work.
Dave
Thank you it works
is working on a reply...