Joel
Joel

Reputation: 33

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

Upvotes: 1

Views: 922

Answers (2)

Ovis
Ovis

Reputation: 391

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"

Upvotes: 0

Tim
Tim

Reputation: 4410

To get properties you need to use the GetProperty() method.

var top = Node.GetCurrent(); top.GetProperty("umbracoNaviHide").Value;

Upvotes: 1

Related Questions