Skip to main content

Content relationships example

This example shows the 3 different ways of structuring your content type schemas to allow users to combine content items: content links, content references and inline content. We also show you how to include a property defined in a partial.

Content links and content references are both ways of defining properties that include content items created from other content types. In both property types, you specify the content types that can be chosen in the contentType enum, as shown in the content_Link and content_Reference properties in the schema below.

However there are some differences between the content links and content references:

  • Using a content-reference you can link to external content items, but retrieve those items only when needed.

  • When you retrieve a content item with a content reference property, the id of the referenced content will be returned, rather than the entire item. You can then use the id to retrieve the linked content when required.

  • When you publish a content item containing a content link then the linked content item(s) are published as well. If you publish a content item containing a content reference, then the content referenced will not be published and will need to be published separately.

  • Content references are particularly useful when working with a content item such as a blog, where you might want to link to several related blogs, but only load one of these blogs when the user requests them.

In the example content section, we've included some example content for a content item created from this schema that shows the differences between content references and content links. You can see that for the content reference, only the ids of the content are returned.

Inline content
Link copied!

With inline content, as shown in the inline_Content property below, you can reference externally defined content and display this inside the same content form. You do this by including the other schema using the $ref keyword. The content is created from an external schema, but the content itself is all included in the same content item, is not managed separately and cannot be shared with other content items.

Properties defined in a partial property
Link copied!

A partial is a content type schema that just contains a "definitions" section. These definitions can be used in multiple schemas. In order to include a property that is defined in a partial, you just need to make sure that the partial is created on your hub. Partials are not registered.

To use the link_from_partial property, the "Various partials" example (https://schema-examples.com/various-partials) must have been created on your hub.

Pre-requisites
Link copied!

In order to use this example, you must register the media example schema (with the URL https://schema-examples.com/media).

How to use
Link copied!

To use this example with your own content types, just update the contentType enum for the content link and reference properties to include your own content types. For the inlineContentExample property, update the $ref with the URL of your own content type.

Content relationships example schema
Link copied!

{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://schema-examples.com/combiningschemas",

"title": "Combining schemas",
"description": "Example showing how to combine content types. Prerequisites: 'https://schema-examples.com/media' must also be registered",

"allOf": [
{
"$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content"
}
],

"type": "object",
"properties": {
"content_Link": {
"title": "Media content item linked",
"allOf": [
{
"$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content-link"
},
{
"properties": {
"contentType": {
"enum": ["https://schema-examples.com/media"]
}
}
}
]
},
"content_Reference": {
"title": "Media content item referenced",
"allOf": [
{
"$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content-reference"
},
{
"properties": {
"contentType": {
"enum": ["https://schema-examples.com/media"]
}
}
}
]
},
"inline_Content": {
"type": "object",
"allOf": [
{
"$ref": "https://schema-examples.com/media"
}
]
},

"link_from_partial": {
"allOf": [
{
"$ref": "https://schema-examples.com/various-partials#/definitions/link"
}
]
}
},

"propertyOrder": []
}

Content form preview
Link copied!

An example of creating a content item using a content type registered from the combining schemas example is shown in the image below.

You'll see that for the inline content property, both the image and video properties from the media content item are shown, while for the content link and content reference, the card is shown for the linked content item.

Adding a content item from the combining schemas content type

Example content
Link copied!

Here is some example content created from a content item using the combining schemas content type. Notice that for the content reference, only the ids of the referenced content are returned, while for the linked content, the entire linked content item is returned.

{
"content":{
"_meta":{
"name":"Combining schemas example",
"schema":"https://schema-examples.com/combiningschemas",
"deliveryId":"be222690-87f2-4883-bf4e-ea0fb43ca76e"
},
"content_Link":{
"_meta":{
"name":"Media example",
"schema":"https://schema-examples.com/media",
"deliveryId":"93e6ba69-921b-4bf2-93dd-f105a05ea018"
},
"image":{
"_meta":{
"schema":"http://bigcontent.io/cms/schema/v1/core#/definitions/image-link"
},
"id":"b667341a-8483-47a1-9ec2-842b5f472577",
"name":"woman-blue-jacket-happy",
"endpoint":"ampproduct",
"defaultHost":"cdn.media.amplience.net"
},
"video":{
"_meta":{
"schema":"http://bigcontent.io/cms/schema/v1/core#/definitions/video-link"
},
"id":"a6879dc9-067f-4132-942e-0c7a10320f81",
"name":"ski-collection",
"endpoint":"ampproduct",
"defaultHost":"cdn.media.amplience.net"
}
},
"content_Reference":{
"_meta":{
"schema":"http://bigcontent.io/cms/schema/v1/core#/definitions/content-reference"
},
"contentType":"https://schema-examples.com/media",
"id":"9609d7f5-4b5a-4e10-a85a-975494c03892"
},
"inline_Content":{
"image":{
"_meta":{
"schema":"http://bigcontent.io/cms/schema/v1/core#/definitions/image-link"
},
"id":"499ceb10-18dc-48be-baa7-306f938928cd",
"name":"womaninfield",
"endpoint":"ampproduct",
"defaultHost":"cdn.media.amplience.net"
},
"video":{
"_meta":{
"schema":"http://bigcontent.io/cms/schema/v1/core#/definitions/video-link"
},
"id":"8b8f047e-e995-45ec-9dee-6d8e1c139ab5",
"name":"sunglasses-promo-video",
"endpoint":"ampproduct",
"defaultHost":"cdn.media.amplience.net"
},
"videotitle":"Sunglasses promo",
"altimagetext":"Woman in field",
"_meta":{
"schema":"https://schema-examples.com/media"
}
},
"link_from_partial":{
"label":"Find out more",
"value":"https://www.example.com"
}
}
}