Copied to clipboard

Flag this post as spam?

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


  • Jeroen Oostwouder 104 posts 300 karma points
    Aug 28, 2015 @ 08:34
    Jeroen Oostwouder
    0

    Randomize a list of Children (DynamicNodeList)

    Hi,

    I want a list of items (nodes) to display on a page in a random order. Is there any way to do that?

    I tried

    node.ChildrenAsList.Where("show").Random()
    

    But that only returns 1 item.

    I've also tried something like this:

    node.ChildrenAsList.Where("show").OrderBy(x => Guid.NewGuid());
    

    But that results in an error too, because I can't use a lambda expression there.

    Any other ideas? I can't be the first that needs to shuffle a list of nodes, can I?

  • Benas Brazdziunas 34 posts 156 karma points c-trib
    Oct 01, 2015 @ 14:24
    Benas Brazdziunas
    0

    It your node is CurrentPage you can use Model.Content instead:

    var random = Model.Content.Children.Where("show").OrderBy(x => Guid.NewGuid());
    
  • Stuart Nisbett 13 posts 59 karma points
    Aug 17, 2018 @ 11:47
    Stuart Nisbett
    1

    easiest way is to use .Random(#) Replace # with the number of results or to display all - if there aren't too many - put in a number which will cover the lot.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies