Copied to clipboard

Flag this post as spam?

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


  • Sean Dooley 289 posts 528 karma points
    Jul 14, 2011 @ 17:27
    Sean Dooley
    0

    Random uComponents Multi-Node Tree Picker

    I have the below code snippet that renders the selected Multi-Node Tree Picker nodes. I'm looking at how to select a random selection of those nodes.

    Model.TreePicker returns umbraco.MacroEngines.DynamicXml - can this be converted to a DynamicNodeList to apply Random? Or is there another way?

    @inherits umbraco.MacroEngines.DynamicNodeContext                                                     
    @{
      if (Model.HasProperty("treePicker") && Model.GetProperty("treePicker").Value != String.Empty) {
        <ul class="features">
          @foreach (var item in Model.TreePicker) {
            var node = @Model.NodeById(@item.InnerText);
        <li>
          <a href="@node.Url">@node.Name</a>
            </li>
          }
        </ul>
      }
    }
  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jul 15, 2011 @ 08:59
    Sebastiaan Janssen
    0

    You're going to have to put the items in a seperate list (var myList = new List<DynamicNode>();) (in your foreach loop, do something myList.Add(node) and then after the foreach you can do myList.Random();

     

  • Sean Dooley 289 posts 528 karma points
    Jul 15, 2011 @ 11:05
    Sean Dooley
    1
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    var nodes =newDynamicNodeList();
    if(Model.HasProperty("treePicker")&&Model.GetProperty("treePicker").Value!=String.Empty){
       
    foreach(var item inModel.TreePicker){
         
    var n =newDynamicNode(@item.InnerText);
          nodes
    .Add(n);
       
    }
       
    <ul class="features">
         
    @foreach(dynamic node in nodes.Random(3)){
           
    <li>
             
    <a href="@node.Url">
               
    @RenderPage("RenderPageMedia.cshtml","thumbnail", node.Thumbnail)
               
    <div class="description">
                 
    @Html.Raw(node.Name)
               
    </div>
              </
    a>
           
    </li>
          }
        </
    ul>
  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jul 15, 2011 @ 11:07
    Sebastiaan Janssen
    0

    Cool! So where did the random go?

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jul 15, 2011 @ 11:10
    Sebastiaan Janssen
    0

    By the way, If you're using 4.7.1, you can do Model.HasValue("treePicker") and you don't have to do the empty string check and hasproperty.

Please Sign in or register to post replies

Write your reply to:

Draft