Custom fields and Content relations API
The following video is an overview and demonstration of the related content feature:
Sitefinity CMS enables you to include related content to content modules from both built-in and dynamic modules, as well as pages. You can relate content to any other content, thus creating complex architectures of structured data that is easily manageable.
You can add relations between content types by adding Related data and Related media custom fields. The custom fields can then be used to create relation between the items of the specified types. You can also create one-to-one or one-to-many relations between different items. Sitefinity CMS makes it easy to display all related items on the frontend. For example, you can relate an image of a doctor to an article about Medical research.
EXAMPLE: Use the Module Builder to create a dynamic module Speakers. The module will store information about different speakers. Create a page where you drop the Speakers widget. Open the Eventsmodule and create a custom field of type Related data and Data type Speakers. In the backend, when you create an event item, you see the custom field added. There you can choose a speaker that will be related to the events item. Then, you add the Speakersfield to the widget template of the Eventswidget. When you open the frontend and click an event item, you will see the details of the event item and the link to the speaker’s details. The speaker’s details are displayed on the page you initially created and dropped the Speakerswidget on.
You can add related data and media to the following built-in modules:
- Blog posts
- List items
You can also add related data and media fields to dynamic module types and to products.
Related content and content providers
When working in a content setup that includes various sources of content, that is, content providers, you need to define where content is saved or obtained from. That is, the destination where content is stored. In multisite environment, unless explicitly configured, your sites have different default providers for content. Thus, there is a clear separation and organization of content.
You can share the content items of built-in and dynamic modules between different sites by sharing the content providers for these content items. Keep in mind that each site stores new content in their default provider and that each module can have different content providers for each site, not necessarily the default provider of the site in question.
In scenarios where you configured a Related media field provider to be “Default source for this site” and each site has a different default provider for the media content, the Related media field displays content only on the site where this content was originally created. You can also set the same default provider for a content type, for example, News, for all sites in your instance. For more information, see Share content providers of modules.
For each content type, to relate content, you add Related data and Related media fields. Each related data or media field can work with one provider or all of the shared providers as sources of content.
Additionally, once you set a provider for the field, you can change it at a later point in time, if required. You can, for example, decide you want to provide content editors with flexibility to use related images from the content sources of all sites, not just one. Thus, they can choose on the go from which source to select related data or media.
NOTE: When working in the classic content editor and you set All sources for the current site option for the related content field, when creating a new related content item from the related content dialog, you can choose the provider, in which the item is stored. On the hand, when you create such a related content item in the new content editor, the item can only be stored in the Default source for this site.
You select a provider for your Related data or Related media fields when:
- Creating a custom field for a built-in module
- Adding fields to dynamic content types
- Creating or uploading and item on the go when editing content
For more information, see Custom fields.
Considerations and dependencies
The following section describes a couple of use cases to consider when working with related data and media and different content providers.
|Change the provider or switch from all providers to just one provider
||You already have a relation between content items, for example, a News item is related to a video via a Related media custom field. You change the provider of the custom field from A to B.
|The relation between the items is persisted in the database, however, the related video is no longer visible on the frontend. If you switch back to provider A, the video will be visible again.
|Add a related item in the content editor
|You set All sources for the current site option for your Related data field of type News. The related items already listed do not fulfill your criteria and you need to create a new related item News.
- Classic interface
You can choose the provider, in which the item is stored.
- New interface
The News item can only be stored in the Default source for this site.
|Upload images in the content editor
|You set All sources for the current site option for your Related media field. However, there are not suitable options listed for your needs. You need to upload new images that reflect your blog post’s topic better.
|When uploading images, you can select the library where to store the image. In addition, you can select the destination, that is the provider, where to upload the image. Based on the destination selected, the list with libraries dynamically changes as well.
|You configured a Related media field provider to be “Default source for this site” and each site has a different default provider for the media content.
|The Related media field displays content only on the site where this content was originally created.
|You set the same default provider A for a content type, for example, Blog posts, for all sites in your instance.
|Content editors working in any of the sites will be able to use content from provider A and this content will be visible on all sites.