umbraco - usercontrols - umbracoNaviHide
I know I can get the current node with 'var top = Node.GetCurrent();' but I cant seem to find where I can get the related properties, specifically 'umbracoNaviHide'. I'd like to know how to access the same data that is开发者_开发百科 accessible from XSLT in a user control
To get properties you need to use the GetProperty() method.
var top = Node.GetCurrent(); top.GetProperty("umbracoNaviHide").Value;
In Umbraco 8, you will have to do something like this:
private List<NavigationListItem> GetChildNavigationList(IPublishedContent page)
{
List<NavigationListItem> listItems = null;
var childPages = page.Children.Where(i => i.IsPublished());
if (childPages != null && childPages.Any() && childPages.Count() > 0)
{
listItems = new List<NavigationListItem>();
foreach (var childPage in childPages)
{
int myTrueFalseFieldValue = 1;
if (childPage.HasProperty("umbracoNaviHide"))
{
Int32.TryParse(childPage.GetProperty("umbracoNaviHide").GetValue().ToString(), out myTrueFalseFieldValue);
//myTrueFalseFieldValue = 0 // hide the page
//myTrueFalseFieldValue = 1 // don't hide the page
string name = childPage.Name;
int test = myTrueFalseFieldValue;
}
if (myTrueFalseFieldValue == 1)
{
NavigationListItem listItem = new NavigationListItem(new NavigationLink(childPage.Url, childPage.Name));
listItem.Items = GetChildNavigationList(childPage);
listItems.Add(listItem);
}
}
}
return listItems;
}
Above code will make sure that those pages which have set there umbrachoNaviHide checkbox property to true will not be included in the navigation list.
In order to see how to make custom property: umbracoNaviHide, please search youtube for "Day11: Hide Pages from Navigation in Umbraco"
精彩评论