Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lee A 3 posts 94 karma points
    May 10, 2019 @ 00:10
    Lee A
    0

    Only display child node if the DocumentTypeAlias is equal to

    Hi there, 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.

  • Lee A 3 posts 94 karma points
    May 10, 2019 @ 06:16
    Lee A
    0

    To simplify the question: How do you only show a child nodes that have a certain name?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 10, 2019 @ 09:14
    Alex Skrypnyk
    1

    Hi Lee

    Use this code:

    @{ var selection = Umbraco.AssignedContentItem.Children.Where(x => x.IsVisible() && x.DocumentTypeAlias.Equals("fAQ"));  }
    @{ var i = 1; }
    @foreach (var item in selection)
    {
        <p>Hello I am an FAQ child node @item.Name</p>
        i+=1;
    }
    

    Model.Content.DocumentTypeAlias == "fAQ" is wrong, because Model.Content - it's current page, so you check is current page FAQ?

    Thanks,

    Alex

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 16, 2019 @ 13:54
    Alex Skrypnyk
    1

    Hi Lee

    Did you solve the issue?

    Alex

  • Lee A 3 posts 94 karma points
    May 16, 2019 @ 20:17
    Lee A
    100

    Hi Alex,

    Thanks for your input. I implemented that code you provided and could not get it to run properly

    I ended up using this code which worked for me. (Not as slick as your solution but it worked)

        @{ var selection = CurrentPage.Children.Where("Visible"); }
        @{ var i = 0; }
        @foreach (var item in selection)
        {
            if(item.DocumentTypeAlias == "fAQ"){
                 <p>Hello I am an FAQ child node @item.Name</p>
            }
            i += 1;
        }
    
  • MB 113 posts 422 karma points
    May 16, 2019 @ 21:53
    MB
    0

    I would have thought perhaps something along these lines...?

    foreach (var item in [pageref].Children.Where(n => n.IsVisible() && n.IsDocumentType("fAQ")))
    { if (item.blah blah blah) }
    
Please Sign in or register to post replies

Write your reply to:

Draft