Replace the default widget view through widget definitions
To customize the default view of a widget type, you actually need to replace the existing widget template with a new one that you create. The new template is a modified version of the existing widget template.
PREREQUISITES:
- You have downloaded the WidgetsTemplates.zip file from the Sitefinity CMS GitHub repository.
- You have unzipped the WidgetsTemplates.zip file and copied the TitlesDatesSummariesListView.ascx file.
Modify the default widget
You now need to replace the default widget view with a custom one:
- Open Visual Studio and in the context menu of your project, click Add » New Item... » Web User Control.
Name the new web user control RaplaceDefaultWidget.ascx
- Paste the contents of the TitlesDatesSummariesListView.ascx file located in the Sitefinity CMS SDK installation folder.
- To extend the template functionality and add dropdown menu, add a RadComboBox.
Use the following markup:
Implement the code behind
Once you create the custom template, you need to implement the code-behind.
Perform the following:
- Create a class and name it RaplaceDefaultWidget.cs
- Make the class inherit from the default Telerik.Sitefinity.Modules.News.Web.UI.MasterListView class.
- In the new class, override the LayoutTemplatePath property of the MasterListView class and point it to the custom template you created.
- Add a reference to the
RadComboBox
controls so you can operate with them.
- Override the InitializeControls method of the MasterListView class and implement our business logic for populating the filter options.
- Once you set the DataSource, bind it to the RadComboBox control.
- Override the GetItemsList() method - this is where Sitefinity CMS constructs the query and gets the associated items. Get the selected value from the categories RadComboBox and apply this value via the SelectVallue property to the filter expression.
- Override the OnPreRender() method.
Use the following code sample:
You now need to For developers: Map the FilterContentViewFrontend template to the News widget with all News widget instances.