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 246 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
Version 8.18.x (untested)

You must login before you can report on package compatibility.

Previously reported to work on versions: 7.5.x, 7.3.x

Package Information

  • Package owner: Jeremy Pyne
  • Created: 04/02/2016
  • Current version 2.2
  • .NET version 4.5
  • License MIT
  • Downloads on Our: 604