In following the v5 documentation to the letter and examples on the site. The where clause doesn't work at all as expected. Usually returning incorrect results. Have tested using the starter kit.
I added umbracoNaviHide as a property on a root node that every other node inherits from.. I have tried this example:
although none of my umbracoNaviHide checkboxes are selected I this will never evaluate to true..
here is my nav code:
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@{
//Maximum level you want to loop down to
var maxLevel = String.IsNullOrEmpty(Model.MacroParameters.maxLevel) ? 3 : Convert.ToInt32(Model.MacroParameters.maxLevel);
//Get the current page
var currentPage = DynamicModel;
//Will walk up the tree to the last ancestor node aka RootNode
var rootNodes = currentPage.AncestorsOrSelf.Last().Children;
<nav role="navigation" class="nav-collapse">
<ul class="nav">
@foreach(var rootNode in @rootNodes) {
bool hasChildren = rootNode.Children.Where("umbracoNaviHide != @0", "True").Any();
@Html.Raw(rootNode.Children.Where("umbracoNaviHide != @0", "True").Count().ToString())
<[email protected](hasChildren ? "class=\"dropdown\"" : "")>
@* Add CSS class selected if rootIsSelected *@
<a href="@rootNode.Url" class="@(currentPage.Id == rootNode.Id ? "selected" : "")">@rootNode.Name</a>
@* Display children on rootNode *@
@childPages(rootNode.Children, maxLevel)
</li>
}
</ul>
</nav>
}
@helper childPages(dynamic pages, int endRenderLevel)
{
//Check we have pages to loop through
if (pages.Any())
{
//Get the navigation level
var naviLevel = pages.First().Level;
if (naviLevel <= endRenderLevel)
{
<ul class="dropdown-menu">
@foreach (var page in pages)
{
//Check the page is not hidden with umbracoNaviHide
if (page.umbracoNaviHide != "True")
{
//Get the page ID in the loop as a HiveID
HiveId pageID = page.Id;
//Check if the current page or any of the ancestor pages contain the page ID and retrun a boolean
var isSelected = Model.CurrentPage.AllAncestorIdsOrSelf().Contains(pageID);
<li>
@* Add CSS class selected if isSelected *@
<a href="@page.Url" class="@(isSelected ? "selected" : "")">
@page.Name
</a>
@* if the current page has any children *@
@if (page.Children.Any())
{
@childPages(page.Children, endRenderLevel);
}
</li>
}
}
</ul>
}
}
}
It appears to be a bug.. and an annoying one at that...
if umbracoNaviHide is checked you get a string value of "True" if it is unchecked instead of returning the string value of "False" that is in the database it returns nothing at all..
the object's WhenItemIsNotFound is null and unfortunately it is a bug.. it doesn't let you perform any of the queries as listed in the docs...
Where Clause Doesn't Work in v5
In following the v5 documentation to the letter and examples on the site. The where clause doesn't work at all as expected. Usually returning incorrect results. Have tested using the starter kit.
I added umbracoNaviHide as a property on a root node that every other node inherits from.. I have tried this example:
http://our.umbraco.org/documentation/v501/Reference/Templating/MacroPartials/Samples/ListChildPageFromCurrentPage
and have tried creating a multi-level nav.. when trying to use .Where("Level == 2") for example or
bool hasChildren = rootNode.Children.Where("umbracoNaviHide != @0", "True").Any();
although none of my umbracoNaviHide checkboxes are selected I this will never evaluate to true..
here is my nav code:
It appears to be a bug.. and an annoying one at that...
if umbracoNaviHide is checked you get a string value of "True" if it is unchecked instead of returning the string value of "False" that is in the database it returns nothing at all..
the object's WhenItemIsNotFound is null and unfortunately it is a bug.. it doesn't let you perform any of the queries as listed in the docs...
screenshot attached:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.