Copied to clipboard

Flag this post as spam?

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


  • Jon-Paul Edwards 6 posts 87 karma points
    May 19, 2016 @ 05:44
    Jon-Paul Edwards
    0

    searching for certain document types

    Hi,

    I am trying to create a variable that will store the document types which contain a property of visibleTopMenu which is a data type of true / false.

    I am trying to collect the documentTypes which contain this property and where the value is true. These documentTypes are nested a couple of rows deep from the home page, but I thought this wouldn't make a difference.

    My code is as follows:

    @{
    var home = CurrentPage.Site();
    var selection = home.Children.Where("visibleTopMenu"); 
    }
    

    selection is returning no values, although there are about 5 documentTypes which have this property set to true. Does anyone know why?

    Thanks for any help provided.

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    May 19, 2016 @ 06:33
    Dennis Adolfi
    100

    Hi Jon-Paul!!!

    Try Descendants inseat of Children.

    @{
    var home = CurrentPage.Site();
    var selection = home.Descendants().Where("visibleTopMenu"); 
    }
    

    home.Children() will only give you the nodes that are directly under your home node, where as home.Descendants() will give you all the nodes under home no matter how many rows (levels) they are nested down.

  • Sotiris Filippidis 286 posts 1501 karma points
    May 19, 2016 @ 07:28
    Sotiris Filippidis
    1

    I agree with Dennis.

    Also, I think you are talking about documents (as in the content tree structure) and not document types, since document types are definitions. Documents are the one which contain the data.

  • Jon-Paul Edwards 6 posts 87 karma points
    May 19, 2016 @ 08:22
    Jon-Paul Edwards
    1

    Hi

    Thanks for the replies. I actually solved it like this:

      var home = CurrentPage.Site();
       foreach (var child in home.Descendants())
        {
    
    
            if (child.GetPropertyValue("visibleTopMenu")==true)
            {
    

    Thanks for your help!

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    May 19, 2016 @ 08:30
    Dennis Adolfi
    1

    Awesome, great job Jon-Paul! Remember however to check that the child has that property, since all the descendants of Home might not have the visibleTopMenu property. You can check this like:

    if (child.HasProperty("visibleTopMenu") && child.HasValue("visibleTopMenu") && child.GetPropertyValue("visibleTopMenu") == true)
    
Please Sign in or register to post replies

Write your reply to:

Draft