Add related data to widgets

You add relations between content types by adding Related data custom fields. The custom fields can then be used to create relation between the items of the specified types.

The following example demonstrates how to add related data to a News widget that displays News widget to display News items' content. You want to also display related news. For example, if the news content is about the latest Sitefinity CMS release, you may also want to display links to related news about new features or previous releases.

You do this by creating a page where you drop the News widget. You create a custom field RelatedNews of type Related data. In the backend, when you create a news item, you see the custom field added and you can choose from a list of news items to be related to the news item you are creating. Then, you add the RelatedNews field to the widget template of the News widget. When you open the site and click a news item, you will see the details of the news item and the link to the related news. 

For more information about creating widget templates, see Modify widget templates.

To add a related data custom field to the News items:

  1. In Sitefinity CMS backend navigate to the Content » News.
  2. Add a custom field named RelatedNews.
  3. Set the type of the custom field to Related data and its data type to News.
  4. Create news items and set the RelatedNews field of any of the news to a custom selection of the rest of the news.

To display the related news links:

  1. To create a new template for the widget's detail view, open the SitefinityWebApp/Mvc/Views/News folder.
    Create a Detail.DetailPageRelatedData.cshtml file. 
  2. Open the Detail.DetailPage.cshtml file and copy its content.
  3. Paste the content in the Detail.DetailPageRelatedData.cshtml file.
  4. Add the following code at the end of the Detail.DetailPageRelatedData.cshtml file:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Tags

Was this article helpful?