Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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> } }
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();
@using umbraco.MacroEngines@inherits umbraco.MacroEngines.DynamicNodeContextvar 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>
Cool! So where did the random go?
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.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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?
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();
Cool! So where did the random go?
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.
is working on a reply...