Additional Data

How to use Additional Data in Open Content

Intro to Additional Data

Additional Data is a way to create lists of reusable data for your templates.
The Addition Data list can be managed from the Module Action Dropdown.
Example of additional data are Categories, Tags, Type etc.
Contrary to other modules there are no predefined categories or tags, you have to add them yourself.
A bit more work but very flexible.

Below we'll explain what to do when you are editing your OC files manually.
Most of this can also be done using the template builder

Steps to add Additional Data

1. Define the schema and options for your additional data.
This is the same as every other Open Content Template data by adding
[name]-schema.json
[name]-options.json
files per type of Additional Data
Where [name] is the name of the Additional Data.
Please note that the [name] of these files will be used to identify the data.

{
    "type": "array",
	"items": {
        "type": "object",
        "properties": {
            "Id": {
                "type": "string",
                "title": "Id (internal)"
            },
            "Title": {
                "type": "string",
                "title": "Category Name"
            }
        }
    }
}
{
    "items": {
        "fields": {
            "Id": {
                "type": "guid",
                "hidden": true
            },
            "Title": {
                "type": "text"
            }
        }
    }
}

This defines the data of the additional data. You need a set of these two files for every type of additional data.

2. Add an Additional Data definition to the Manifest.

You need to define the Additional Data in the manifest

{
    ...
	
    "templates": {
        ...
    },
	"additionalData": {
			"Categories": { /* This should be equal to [name] */
				"title": "Article Category",
				"scope": "module" /* tabmodule, module, tab, portal */
			}
		}

}

"title" is the Title you will see in the Module action drop-down for editing.
"scope" sets on what level the data is stored, meaning you can can limit the Categories available to the Portal, Page, or Module.

You can also set "additionalDataInTemplate": true, for a template in the manifest.
In that case the complete set of additional data is available as as separate branch for that template, not only the data that is assigned to your Items.
This can be useful when you want to show / loop over a list of all existing categories for instance. To avoid passing a very large object that's not used, this is an option that is off by default.

3. Add the Additional Data to your Main template

{
    "type": "object",
    "properties": {
			"Title": {
				"title": "Title",
				"type": "string"
			},
			"Intro": {
				"title": "Intro",
				"type": "string"
			},
			"Text": {
				"title": "Text",
				"type": "string"
			},
			"Categories": {
			  "type": "string",
			  "title": "Category (single)"
			}
		}
}
{
	"fields": {
		"Intro": {
			"title": "Introduction",
			"type": "textarea"
		},
		"Text": {
			"title": "Text",
			"type": "ckeditor"
		},
		 "Category": {
		  "type": "select2",
		  "dataService": {
			"action": "LookupData",
			"data": {
			  "dataKey": "Categories",
			  "valueField": "Id",
			  "textField": "Title"
			}
		  }
		}
	}
}

This way you should be able to add and edit "Categories" from the Module action menu and assign them to your items.
When you want the your Additional Data to be available as Multi Select (multiple categories) the only thing you need to do is; change the "type" in this schema from "array" to "string". (and probably change the Titles from Category to Categories)

Use Additional Data in your Template

You can use the data that is part of your Open Content data in your templates (as an example the categories assigned to an item).
But when you want to show the defined Additional data on it's own (example: a list of all categories) you need to add an attribute to the manifest to include them in the data for your template: "additionalDataInTemplate": true

"templates": {
        "list": {
            "type": "multiple",
            "title": "List",
            "main": {
              "template": "template.hbs",
             	"additionalDataInTemplate": true
            },
            "detail": {
                "template": "detail.hbs",
                "additionalDataInTemplate": true
            }
        }
}

Errors with additional data

Errors in schema/options files could result in a blank edit/builder screen.

Whenever you reference a non-existing addtional data field, you will get an server error like: "DesktopModules/OpenContent/API/OpenContentAPI/LookupData:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)".

Examen the error in detail and you will find the missing key of the AdditionalData definition.
The solution is to either:

  • Remove this field from the schema/options file or
  • add the to the field manifest and schema/options as prescribed above (Steps to add Additional Data)