English 中文(简体)
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>   
}
最佳回答

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.

问题回答

you can simply do it like

@foreach (var child in root.Children.Where("umbracoNaviHide != true &&  NodeTypeAlias == "DocumentTypehere" ")
{
    <li>@child.Name</li>   
}

You can just write for your check on umbracoNaviHide:

if (!child.umbracoNaviHide)
{
    continue;
}
<li>@child.Name</li>

Just to add another approach - a few of the existing answers did not work for me - you can try this. Works for me in Umbraco 4.11

@foreach (var child in root.Children.Where(child => child.GetPropertyValue("umbracoNaviHide") == "0"))
{
..
}




相关问题
Creating custom content sections with umbraco

I m working on an umbraco website just now and one of the requirements is to have a custom section in the back end that can be used to manage publish smaller micro-sites. I have been able to create ...

MVC and Umbraco integration

I ve followed the steps from http://memoryleak.me.uk/2009/04/umbraco-and-aspnet-mvc.html and integrated MVC in Umbraco with success, but I still have a problem which is critical for me. Is there any ...

Umbraco server error after install

I downloaded umbraco and used the web platform installer. Everything went though okay and it installed SQL Express 2008 and a new directory under the default website in IIS. However when I launch the ...

XSLT, sort and group by year-date

Regarding Umbraco XSLT version 1. I have aprox. 150 news items in XML. Lets say like this (all is pseudocode until I get more familiar with this xml/xslt): <news> <data alias=date>2008-...

Open node in Umbraco programmatically

I have created a dashboard for an Umbraco site and I want to link from it to various node in the tree. From what I can tell Umbraco uses editcontent.aspx?id={thenodeid} and javascript:opencontent({...

Umbraco Back Office Membership Provider

Has anyone had any experience trying to write a custom Membership Provider for the Umbraco back office? I ve run into all sorts of trouble trying to make this happen. You can see some more details ...

热门标签