Search code examples
asp.netrazorumbracoumbraco7

Umbraco Only display child node if the DocumentTypeAlias is equal to


I am using Umbraco 7. I have a parent node with 2 different types of child nodes.

About

--Bio 1 (Child node type 1)

--Bio 2 (Child node type 1)

--FAQ 1 (Child node type 2)

--FAQ 2 (Child node type 2)

What I want to do is only display one type of child node ie if the child node document type is == to "fAQ" show FAQ

    @{ var selection = CurrentPage.Children.Where("Visible") && Model.Content.DocumentTypeAlias == "fAQ";  }
    @{ var i = 1; }
    @foreach (var item in selection)
    {
  <p>Hello I am an FAQ child node</p>
        i+=1;
    }

My problem is coming from the Model.Content.DocumentTypeAlias == "fAQ"; i think...

I cant figure this one out for the life of me. Any help is appreciated.


Solution

  • You should be able to just do:

    var children = new List<IPublishedContent>();
    if (Model.Content.DocumentTypeAlias == "fAQ") { 
       children = Model.Content.Children().Where(i => i.IsVisible());
    }
    

    If you want to only display child nodes of type "fAQ", you can do the following:

    var children = Model.Content.Children().Where(i => i.DocumentTypeAlias == "fAQ" && i.IsVisible());