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 referencesLink copied!
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 contentLink 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 propertyLink 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-requisitesLink copied!
In order to use this example, you must register the media example schema (with the URL https://schema-examples.com/media
).
How to useLink 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 schemaLink copied!
Content form previewLink 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.
Example contentLink 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.