The following sample creates a Hello World widget. It demonstrates how to create a ViewComponent class that is used to display a configurable message.
ViewComponent
The sample uses the [SitefinityWidget] attribute to load the widget automatically in the Sitefinity InsertWidget dialogs.
[SitefinityWidget]
InsertWidget
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.
For Sitefinity to be able to detect and render your functionality inside your pages, you must inherit the ViewComponent.
The InvokeAsync method is required. It is called automatically every time the page is requested. The InvokeAsync method needs an argument of type IViewComponentContext. The argument is directly populated in the method when the page is rendered.
InvokeAsync
IViewComponentContext
The generic parameter refers to the Entity of the widget. In addition to your business logic, the Entity contains all properties of the widget, which are persisted in Sitefinity.
Entity
The widget has the following properties that you can use to modify the appearance and the functionality of the widget:
Title
Category
EmptyIcon
EmptyIconText
EmptyIconAction
EmptyLinkAction
None
Edit
SeparateWidgetPerTemplate
NOTE: Only the public properties from the Model are persisted. The public properties that you may have in the ViewComponent.cs file are not persisted. This way, Sitefinity ensures separation between your business logic and rendering.
Model
ViewComponent.cs
Under your Renderer project, you must create the following folders:
Entities
HelloWorld
ViewComponents
Views
Shared
Components
In Visual Studio, open the Renderer application.
Renderer
Entities/HelloWorld
View
Views/Shared/Components/HelloWorld
Build your solution.
When you open your Renderer application and open the New editor, you will see the Hello World widget in the widget selector. When you add the widget on your page and click the Custom empty text link, you can enter a text string that will be displayed on the frontend.
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/hello-world
hello-world.sln
appsettings.json
“Sitefinity”
“Url”
hello-world
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