asp.net-mvc-3razorumbracoumbraco5

umbracoNaviHide not working in Where statement


Trying to get children of a given document type, with umbracoNavihide not set to false:

The following produces correct output.

@foreach (var child in root.Children.Where("ContentTypeAlias == \"DocumentTypehere\""))
{
    if (child.umbracoNaviHide == "False")
    {
        continue;
    }
    <li>@child.Name</li>
}

This does not:

@foreach (var child in root.Children.Where("umbracoNaviHide == @0 && ContentTypeAlias == \"DocumentTypehere\"","False"))
{
        <li>@child.Name</li>   
}

Solution

  • umbracoNaviHide is not supported in Umbraco 5 as per the words of Niels Hartvig:

    While these special aliases does [sic] [recte: do] a great job and are super easy to use (albeit totally impossible to discover if you don't stumble across docs that mention their usage), the problem with these are that they're 'magic' strings which really is a mess (read: They're hacks inside the core).

    So they won't come back in v5 in the form we know from v4.

    So, besides the Linq imitations being somewhat broken anyway, the short answer is that this (either form) shouldn't work (nor should Athul's answer).

    The long answer is that you could use this property (and others like it) only if you explicitly support it as part of your Document Type. There is a feature request, though, asking for the 'built-in' umbraco... properties here should you care to follow and support it.

    I would personally ask that you don't, however; as using these properties and relying on them are problematic (not least for the point mentioned by Neils himself). Make your own, dedicated properties that are aptly aliased for their task.