I have gotten a bit stuck here and looking for som guideance.
So I have an Neasted content data type. And I want to fetch the values in a controller.
I can fetch the first Neasted content byt doing something like this var foo = settingsNode.Properties.Where(x => x.PropertyTypeAlias == backgroundPickerAlias); and that becomes an Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty. But I am having touble fetching the values. By doing foo .Value I get object <string>, but I can't figure out how to get the value of the object. I have been trying to do some LINQ statement, like "Select" and "Where" but it says 'object' does not contain a definition for 'Where' and the best extension method overload PublishedContentExtensions.Where(IEnumerable<IPublishedContent>, string)' requires a receiver of type 'IEnumerable<IPublishedContent>'
You can retrieve a Nested Content's property values in the format of an IEnumerable of IPublishedContent - there is an individual IPublishedContent item representing each repeating Nested Content Item.
Have a look at the reference page in the docs for some examples and explanation:
But essentially if your NestedContent Property type has alias "backgroundItems"
you would be able to get the list of repeating items like so:
var allBackgroundItems = settingsNode.GetPropertyValue<IEnumerable<IPublishedContent>>("backgroundItems");
then you could loop through each of these items and read the individual properties for each repeated element eg
@foreach (var backgroundItem in allBackgroundItems){
//use the alias of the properties of the repeating document type to read the values eg: if there were a 'title' property
var backgroundItemTitle =
backgroundItem.GetPropertyValue<string>("title");
var backgroundImage =
backgroundItem.GetPropertyValue<IPublishedContent>("backgroundImagePicker");
}
unless I've misunderstood what you are trying to do!
What I am trying to achive is to get the background Image in a Neasted Content, on the newly saved node and save that url somwhere.
So I am using theCustomApplicationEventHandler for the "on save event".
I have tried your suggested method, but I would only recive the Published content, but it's not published yet, So this would only work if I where to save and publish 2 times in a row. That's why I trying to get the value via the "Properties" value.
ahh yes, sorry I misunderstood, context is everything!
I think, if you are working with an IContent object in the Save event the value, will currently be a blob of JSON for the Nested Content property you are saving, and so you will need to deserialise it first to start reading the values:
var nestedItems = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(settingsNode.GetValue<string>("nestedContentPropertyAlias"));
then you can loop through the list of dictionary items and their values...
Neasted content value in controller
Hello Evryone!
I have gotten a bit stuck here and looking for som guideance.
So I have an Neasted content data type. And I want to fetch the values in a controller.
I can fetch the first Neasted content byt doing something like this
var foo = settingsNode.Properties.Where(x => x.PropertyTypeAlias == backgroundPickerAlias);
and that becomes anUmbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty
. But I am having touble fetching the values. By doingfoo .Value
I getobject <string>
, but I can't figure out how to get the value of the object. I have been trying to do some LINQ statement, like "Select" and "Where" but it says'object' does not contain a definition for 'Where' and the best extension method overload PublishedContentExtensions.Where(IEnumerable<IPublishedContent>, string)' requires a receiver of type 'IEnumerable<IPublishedContent>'
I can't figure this out to save my life..
I am open to everything!
//Johannes
Hi Johannes
You can retrieve a Nested Content's property values in the format of an IEnumerable of IPublishedContent - there is an individual IPublishedContent item representing each repeating Nested Content Item.
Have a look at the reference page in the docs for some examples and explanation:
https://our.umbraco.com/Documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Nested-Content/index-v7
But essentially if your NestedContent Property type has alias "backgroundItems"
you would be able to get the list of repeating items like so:
then you could loop through each of these items and read the individual properties for each repeated element eg
unless I've misunderstood what you are trying to do!
regards
marc
Hi Marc!
Thank you for your reply!
What I am trying to achive is to get the background Image in a Neasted Content, on the newly saved node and save that url somwhere.
So I am using the
CustomApplicationEventHandler
for the "on save event".I have tried your suggested method, but I would only recive the Published content, but it's not published yet, So this would only work if I where to save and publish 2 times in a row. That's why I trying to get the value via the "Properties" value.
//Johannes
Hi Johannes
ahh yes, sorry I misunderstood, context is everything!
I think, if you are working with an IContent object in the Save event the value, will currently be a blob of JSON for the Nested Content property you are saving, and so you will need to deserialise it first to start reading the values:
then you can loop through the list of dictionary items and their values...
hope that gets you further down the line!
regards
Marc
Sorry about that!
You are an absolute legend Marc! Thank you so much!
//Johannes
is working on a reply...
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.