Use the Share data between widgets sample to create two widgets that work together in the following way:
CategorySelector
DataToFilter
NOTE: You must place the widgets on the same page.
This sample shows how two widgets can communicate with each other in the early stage of the pipeline.
The sample takes advantage of the IRequestPreparation class, which is executed prior to the page execution. This is useful in the following cases:
IRequestPreparation
IRestClient
NOTE: The IRequestPreparation implementation must be registered in the DI container during startup.
The implementation in this sample monitors the unresolved segments in the URL – for example:
cat1
UrlParameters
cat1, cat2
If there is a match with the existing segments, then MarkUrlParametersResolved() method is called to notify the underlying framework that the additional parameters are resolved and this is a valid URL. If an invalid URL is requested, for example - /cat4 or /cat1/cat2, then the Renderer will return a 404 response. When a match is successful, the resolved parameter is added to the state of the CategorySelector and DataToFilter widgets, so they can display their views according to the current selection.
MarkUrlParametersResolved()
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
ViewComponents
ViewModels
Views
Shared
Components
The example takes advantage of the IRequestPreparation class.
CategoryPreparation
Renderer
Entities/CategorySelector
Entities/DataToFilter
Views/Shared/Components/CategorySelector
Views/Shared/Components/DataToFilter
You must register the IRequestPreparation class in the Program.cs. You must add the following line: builder.Services.AddSingleton??IRequestPreparation, CategoryPreparation??()??column
Program.cs
builder.Services.AddSingleton??IRequestPreparation, CategoryPreparation??()??column
The Program.cs file should look similar to the following:
Build your solution.
When you open your Renderer application and open the New editor, you will see the CategorySelector and DataToFilter widgets in the widget selector. You must add the widgets on the same page and them you can use the filter 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/share-data-between-widgets
share-data-between-widgets.sln
appsettings.json
“Sitefinity”
“Url”
share-data-between-widgets
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