Filter dynamic content items by related data

Similar to filtering the related data items for standard widgets, dynamic MVC widgets also support filtering by related data items.

The following tutorial describes how to filter dynamic content items by related data items via the URL. For more information about creating the module and its content types, see Create Travelling agency site with hierarchical types
Once you activate the dynamic module, a corresponding section is created in Sitefinity CMS toolbox with both Standard and MVC widgets reflecting the names of the content types.

EXAMPLE: For a module with name Travelling Agency, section with name Travelling Agency is created. For Countries dynamic content type, two widgets are automatically added to the toolbox section - Countries and Countries MVC.

PREREQUISITES: You have added Related data custom field of type News to the Cities dynamic content type and name the field CityGuide.

Perform the following:

  1. Create new page with name RelatedData that uses the Bootstrap.default template.
  2. Drag the News MVC widget on the page.
  3. Drag the Cities MVC widget on the page.
  4. Click the Edit button of the Cities MVC widget.
  5. Click the Advanced » Model.
  6. Set the following related data properties:
    • RelatedFieldName
      This is the name of the related data field.
      Enter CityGuide
    • RelatedItemType 
      This is the full type name of the related data field.
      Enter Telerik.Sitefinity.News.Model.NewsItem
    • RelationTypeToDisplay 
      This is the relation type that specifies whether related items are children or parents of the source item.
      Enter Parent
    • RelatedItemProviderName 
      This is the name of the provider that the related data uses.
      Leave empty.
  7. Click Save, publish the page, and open it on the frontend.
    You will see all cities and all news items on the page.
  8. Click on a city name.
    For example, if you click Plovdiv the URL will be in the form of http://domain:xxxx/relateddata/bulgaria/plovdiv.
    As a result you will be navigated to the detail view of the city and news items will be filtered so that only those which are related to the city are displayed. 

Tags

Was this article helpful?