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.
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.
ContentBlockModel
IContentBlockModel
InitialzieViewModel
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.
ContentBlock
Default
Views/Shared/Components/SitefinityContentBlock
Once the extended model is ready, you can register it in the Program.cs file after the registration of the default ComponentView models.
Program.cs
ComponentView
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.
Under your Renderer project, you must create the following folders:
Entities
Models
ViewModels
Views
Shared
Components
SitefinityContentBlock
Entity
Model
View
You must register the ExtendedContentBlockModel and the ExtendedContentBlockEntity class in the Program.cs.
ExtendedContentBlockModel
ExtendedContentBlockEntity
The Program.cs file should look in the following way:
Build your solution.
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.
Renderer
This sample is available in Sitefinity’s GitHub repository. You can run and play with it. To do this, perform the following:
sitefinity-aspnetcore-mvc-samples-master/src/extended-content-block
extended-content-block.sln
appsettings.json
“Sitefinity”
“Url”
extended-content-block
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
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.
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.
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.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important