Example: Related data and custom widgets

As the RelatedDataField is using different controls to display related items in backend and widgets in the frontend, you can configure the related data field to use a custom widget for both. In order to change the frontend widget with a custom one, do one of the following:

Register the custom widget via full type name
If you choose this approach, the custom widget you create must inherit from SimpleView and IRelatedDataView. You also must override the LayoutTemplatePath. You have access to the controls through GetControl method of the current container.

you bound the controls on PreRender using the extension methods exposed for related data. Calling this.DisplayRelatedData() configures the current view and you can retrieve the related items using the GetRelatedItems method.

Code-behind

Widget markup

NOTE: If the widget does not implement ContentView or DynamicContentView, or if it does not have a property ControlDefinition, the widget must be replaced from the widget template inserted on the page.