The code below works without any problems but I have made it 2 years ago and I am thinking that maybe there is a better and easier way to do it. At the moment I am showing a slider on the frontpage and the data is stored like you see below:
The code looks like this:
@{ var rootNode = new umbraco.MacroEngines.DynamicNode(-1);
var dataNode = rootNode.Children.Items.SingleOrDefault(x => x.NodeTypeAlias == "Data"); var dataNodeChildren = dataNode.Children as umbraco.MacroEngines.DynamicNodeList;
var featuresBase = dataNodeChildren.Items.SingleOrDefault(x => x.NodeTypeAlias == "Slider"); var featuresBaseChildren = featuresBase.Children as umbraco.MacroEngines.DynamicNodeList;
foreach (dynamic testimonial in featuresBase.Children) { if (testimonial.NodeTypeAlias == "SliderItem") { <h1>@testimonial.GetProperty("text").Value</h1> } } }
I would say that you should consider using a content picker on your frontpage where you can point to the "Slider" of choice from the "Data" root.
That way you just need to look at the id for the slider, instead of hardcoding it.
This makes it possible to have more than one slider :)
In regards to the Razor code...well it can most likely be refactored but I'll let some of the brighter Razor wizards in here get into details with that for now.
Show data from root on frontpage
Hi,
The code below works without any problems but I have made it 2 years ago and I am thinking that maybe there is a better and easier way to do it. At the moment I am showing a slider on the frontpage and the data is stored like you see below:
The code looks like this:
Could this be done easier and more clean?
// René
Hi René
I would say that you should consider using a content picker on your frontpage where you can point to the "Slider" of choice from the "Data" root.
That way you just need to look at the id for the slider, instead of hardcoding it.
This makes it possible to have more than one slider :)
In regards to the Razor code...well it can most likely be refactored but I'll let some of the brighter Razor wizards in here get into details with that for now.
/Jan
Hi Jan
That's just perfect, your solution works great. :-)
Thanks!
The code now looks like this:
// René
Hi René
Glad that I could inspire you to writing some more efficient code :)
/Jan
is working on a reply...