Sample: Extend the Content block widget
Overview
This sample provides an example on how to extend the Content block widget by replacing its model and the default entity type, which enables you to add additional properties to the designer.
This example demonstrates how to extend the model of the Content Block widget with custom logic and add an additional property in the designer.
Implementation
If you want to extend and slightly modify the logic, you need to inherit the ContentBlockModel
. If you want to apply a new logic to the widget, you need to implement the IContentBlockModel
interface. In the InitialzieViewModel
method you can modify the generated view model that will be passed to the view, or provide additional data to the view, like in the ExtendedContentBlockModel.cs
.
You can modify the view of the ContentBlock
widget by placing a Default
view in Views/Shared/Components/SitefinityContentBlock
folder, and changing the default code of the view depending on your requirements.
Once the extended model is ready, you can register it in the Program.cs
file after the registration of the default ComponentView
models.
PREREQUISITES: You must set up a Sitefinity renderer application and connect it to your Sitefinity CMS application. For more information, see Install Sitefinity in ASP.NET Core mode.
NOTE: The instructions in this sample use Visual Studio 2022 and a Sitefinity renderer project named Renderer.
Folder structure
Under your Renderer project, you must create the following folders:
Entities
Models
ViewModels
Views
/Shared
/Components
/SitefinityContentBlock
Create the widget
- In the context menu of folder
Entities
, click Add » Class…
- In Name, enter ExtendedContentBlockEntity.cs and click Add.
- In the class, paste the following code and save your changes:
- In the context menu of folder
Models
, click Add » Class…
- In Name, enter ExtendedContentBlockModel.cs and click Add.
- In the class, paste the following code and save your changes:
- In the context menu of folder
ViewModels
, click Add » Class…
- In Name, enter ExtendedContentBlockViewModel.cs and click Add.
- In the class, paste the following code and save your changes:
- In the context menu of folder
Views/Shared/Components/SitefinityContentBlock
, click Add » Class…
- Select Code File.
- In Name, enter Default.cshtml and click Add.
- In the class, paste the following code and save your changes:
Register the extended model and entity
You must register the ExtendedContentBlockModel
and the ExtendedContentBlockEntity
class in the Program.cs
.
The Program.cs
file should look in the following way:
Build your solution.
Result
When you open your Renderer
application and open the New editor, you will see the Content block widget in the widget selector. When you add the widget on your page, you can see its modified look.

Run the sample
This sample is available in Sitefinity’s GitHub repository. You can run and play with it.
To do this, perform the following:
- Go to Sitefinity’s GitHub repository Sitefinity ASP.NET Core samples.
- Expand Code and click Download ZIP.
- Extract the files on your computer.
- In the extracted folder, navigate to
sitefinity-aspnetcore-mvc-samples-master/src/extended-content-block
folder.
- Open the
extended-content-block.sln
in Visual Studio.
- Open the
appsettings.json
file.
- In section
“Sitefinity”
, change the “Url”
property to the URL of your Sitefinity CMS site.
If you have deployed Sitefinity CMS on the IIS, point to “https://localhost:<https_port>".
- In Visual Studio, in the context menu of
extended-content-block
project, click View in Browser.
- Log in to your Sitefinity CMS instance and place the widget on a page.