Related media custom field
You use this field to add an option to attach media to a content item in the backend and then display the media together with the item on the frontend.
EXAMPLE: You add an image custom field to the News module. Then, you create a news item. You can see the custom field and you can use it to add one or more images to the news item. Then, you must add the image custom field to the widget template of the News widget. When you drop the widget on a page, the website displays news and images.
You can add a media field to built-in and dynamic modules and pages. The supported media types are images, videos, and files.
To add a media field to a module or page, perform the following:
- Perform procedure Create custom fields » Step 1 to Step 5.
- In Type, select Related media (images, videos, files).
- In Type of media managed by this field, select one of the following:
- Documents or other files
- Click Continue.
The Add a field window appears.
- In Source, select the provider you want to store the related media items.
You can choose between:
- The default source for this site
- Any other provider that is set up
- All sources for the current site
IMPORTANT: When working in multisite, unless explicitly configured, your sites have different default providers for content. You can share content between sites but each site stores new content in its default provider. For more information, see Share content providers of modules.
You can change the provider you select at this step at a later point in time. Keep in mind that when changing providers, the related media field's provider changes dynamically as you switch sites to the default provider for the current site. You can also set the source to be all shared providers. To learn about the implications when changing providers, see Custom fields and Content relations API » Considerations and dependencies.
- Under Interface widget for uploading or selecting images, select the widget you want to use in the backend to upload or select an uploaded media file.
By default, images are uploaded with the Image selector, videos – with the Videos selector, and documents and other files – with the File selector.
- In the Label input field, enter the label of the media selector in the backend.
This label is displayed when you create a content item in the backend.
For example, News images.
- In Instructional text, enter instructions or explanatory text for the custom field, if needed.
The text is displayed when the content editor clicks the question mark icon in the backend when editing the item containing this custom field.
- Select the This is a required field checkbox if you want to make the custom field mandatory.
- In the Label input field, enter the label of the media widget.
For example, Watch video.
- In the How many files can be uploaded or selected? radio button, select if you want to allow multiple media files to be uploaded.
- In the Max file size can be uploaded field, enter the maximum file size in MB.
- Under Allowed file types, perform one of the following:
- If you are adding images or videos as related media, select the checkboxes of the file types that you allow. If the files that you want to allow are not in the list, enter the allowed file type extensions in a comma-separated list in the Other textbox.
- If you are adding documents and other files as related media, select whether you want to allow all file types or only selected file types. If the file types that you want to allow are not in the list of selected file types, enter them in a comma-separated list in the Other textbox.
- Click Done.
The new field appears in the Custom fields section.
- Click Save changes.
- Insert the custom field in the respective widget template.
For example, if you want to relate News to Images, you must insert the images custom field in the widget template that you use to display news items.
For more information, see Create and edit widget templates.