Search code examples
umbracoumbraco7

Umbraco 7.5.1 umbracoNaviHide


To be able to filter out items that should not be rendered with .Where("Visible") I need a property called umbracoNaviHide that returns true or false.

In earlier versions this was added to the Generic tab. However now you cant append to that tab anymore.

How would I accomplish hiding pages now?

Here's my foreach:

 @foreach (var Area in Model.Content.Children.Where("Visible"))
 {

Here's a statement about it. But I cant find any workaround.

Related Changes Summary - 7.4 beta - Option toCannot add properties to the "Generic properties" tab

Description - In the 7.4 beta it's not possible anymore to add properties to the "Generic properties" tab. I know this has been done because properties can be a bit hidden on that tab and usually are better on a separate tab. But there are situations where the properties are better on that tab.


Solution

  • You can add that property as a true/false datatype to any tab. However, it's important to note that umbracoNaviHide does not do anything special it is just a magic string, that, when implemented as a true/false datatype, it works with

    .Where("Visible"). 
    

    Personally I don't use it anymore. If I need to cause items to be visible or not then I would name the property more specifically. For example, it is often useful when implementing menus where you want some nodes to be visible but not others. I generally have a Menu tab where one of the properties is a true/false type called Show in menu with an alias of showInMenu.

    In code it could be something like below (I have used TypedContentAtXPath to get the parent node of a specific doc type. Of course there are various ways of doing this)

    var homeNode = Umbraco.TypedContentAtXPath("//MyHomePageDocType").First();
    var menuItems = homeNode.Children.Where(item=>item.GetPropertyValue<bool>("showInMenu"));
    
    foreach(var item in menuItems)
    {
        // Do your menu stuff here
    }
    

    Hope that helps

    J