0 votes

Nested Data Type

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.

Screenshots

Package owner

Jeremy Pyne

Jeremy Pyne

Jeremy has 244 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
8.5.x (untested)
8.4.x (untested)
8.3.x (untested)
8.2.x (untested)
8.1.x (untested)
8.0.x (untested)
7.15.x (untested)
7.14.x (untested)
7.13.x (untested)
7.12.x (untested)
7.11.x (untested)
7.10.x (untested)
7.9.x (untested)
7.8.x (untested)
7.7.x (untested)
7.6.x (untested)
7.5.x (100%)
7.4.x (untested)
7.3.x (100%)
7.2.x (untested)
7.1.x (untested)
7.0.x (untested)
6.1.x (untested)
6.0.x (untested)

You must login before you can report on package compatibility.

Package Information

  • Package owner: Jeremy Pyne
  • Created: 04/02/2016
  • Current version 2.2
  • .net Version 4.5
  • License MIT
  • Downloads on our: 493