Copied to clipboard

Flag this post as spam?

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


  • MB 273 posts 936 karma points
    May 18, 2016 @ 11:29
    MB
    0

    Count children childrens hasproperty

    Mjellow guys!

    I'm trying to make a gallery frontpage with 3 functions:

    1. Show categories using CurrentPage.Children() - Which works
    2. Using a foreach I count how many images/subpages each category has using item.Childrent.Count() - which works
    3. The last thing which does NOT work is counting how many of each subpage has a file uploaded in a File Uploader.

    See code here: http://pastebin.com/nHsqbAxR And here's a demonstration which, hopefully can help you understand what I wish to accomplish: not my best image

    I hope this is sufficient informations, otherwise let me know and thank you for reading this! :o)

  • David 5 posts 88 karma points
    May 18, 2016 @ 12:04
    David
    1

    Hi Mike,

    I believe you can just use a .Where() when you count the number of items. So on line 13 in your example, use something like this…

    var countSubpages = item.Children.Where("fileUploadAlias != null").Count();
    

    Hope this helps?

    David.

  • MB 273 posts 936 karma points
    May 18, 2016 @ 13:56
    MB
    0

    Hey David,

    Thank you for your response! The value returned from the above code is the same as the number of children.

    I tried writing the code like this:

            var projectFiles = category.Children.Where("projectFiles" != null).Count();
    

    but this returns the Children count aswell.

Please Sign in or register to post replies

Write your reply to:

Draft