This package adds a Nested Datatype to Umbraco that can be used to create complex datatypes that are collections of one or more sets of existing data types.
Each instance can be configured with a list of child properties from those available in Umbraco. In addition the instance can be set to have a single child item, or an array of children items.
The data will be stored as a JSON array and get be easily retrieved with code like this.
@using Newtonsoft.Json.Linq;
var data = Model.Content.GetPropertyValue<JArray>("property");
foreach(var item in data.Children()) {
var name = (string)item["subPropertyAlias"];
@name
}
Or another example retrieving a single field directly.
@CurrentPage.productLinks[0].LinkDocument
Another option is to add a Strong Typed Model and a Property Value Converter for each data type created with this package like so.
https://gist.github.com/pynej/576b138748daef2925b6526b7d56bca8
Then you can simply do the following.
Model.Content.GetPropertyValue<School>(“property”).HasSchool(“Bob”)
Model.Content.GetPropertyValue<School>(“property”).Single(s => s.Name == “Bob”).Level
Or with the Umbraco Model Builders feature set up the following.
Model.Content.MyProperty.Sum(s => s.Level)
Note that the stored data is always an array even if the definition only allows one child.
Update 12/29/1016- Users no longer need settings or developer permissions to edit documents using this data type.
Bugs