I'm a bit of a newbie to Razor so not sure how this is done, any help would be appreciated. I have a list of nodes in the uComponents Multi Node Picker (alias: testimonials) which I grab using:
@Model.testimonials
Due to the nature of the design/HTML I've to spit out, I'd like to split the contents of this list into three separate variables and then iterate over each one separately in a @foreach. It would get messy if I had to process the whole list all in one go. I tried the code below but this generates an error "'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'Take'" because I guess Take is only for Collections not DynamicXml.
var columnOne = testimonials.Take(2); var columnTwo = testimonials.Skip(2).Take(2); var columnThree = testimonials.Skip(4).Take(1);
I'm fairly confident I could come up with a solution in XSLT but am trying to learn the Razor way.
That's what I'd do if I wanted to process all my nodes in one loop but I want to split the list up into 3 variables e.g. the first two list items into a variable named columnOne, items 3 and 4 into columnTwo and the remaining items into a variable named columnThree. Then I would loop through each of these variables individually.
Best way to get specific items from DynamicXml?
Hey,
I'm a bit of a newbie to Razor so not sure how this is done, any help would be appreciated. I have a list of nodes in the uComponents Multi Node Picker (alias: testimonials) which I grab using:
Due to the nature of the design/HTML I've to spit out, I'd like to split the contents of this list into three separate variables and then iterate over each one separately in a @foreach. It would get messy if I had to process the whole list all in one go. I tried the code below but this generates an error "'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'Take'" because I guess Take is only for Collections not DynamicXml.
I'm fairly confident I could come up with a solution in XSLT but am trying to learn the Razor way.
Thanks,
Pat
You would do something like this:
For a list of available properties for the url picker, see this post.
Hey Douglas, thanks for the reply.
That's what I'd do if I wanted to process all my nodes in one loop but I want to split the list up into 3 variables e.g. the first two list items into a variable named columnOne, items 3 and 4 into columnTwo and the remaining items into a variable named columnThree. Then I would loop through each of these variables individually.
Thanks,
Pat
Ah, I see. DynamicXml, unfortunately doesn't provide much flexibility. But you load the DynamicXml values into a List simular to this:
Thanks Douglas, that worked!!
There is a proper fix coming in 4.11:
http://issues.umbraco.org/issue/U4-1207
is working on a reply...