I've done this recently, I needed to add something like:
Showing results for {Keyword}
What I did is to create a new custom search results count out of the OOTB Search Results count SXA rendering, I did the following:
- Create a custom model that is similar to the search results model count but renaming two properties as following:
public string ResultsCountTextFieldName
{
get;
set;
}
public string ShowingResultsForTextFieldName
{
get;
set;
}
- Create a controller for your new custom rendering, something like:
public ICustomResultsCountRepository Repository
{
get;
set;
}
public ActionResult CustomResultsCount()
{
return PartialView(GetModel());
}
public CustomResultsCountController(ICustomResultsCountRepository repository)
{
this.Repository = repository;
}
protected override object GetModel()
{
return this.Repository.GetModel();
}
- Repository that get the model from the data source item (template extended from the OOTB by adding the new string field), similar to:
public override IRenderingModelBase GetModel()
{
CustomSearchResultsCountRenderingModel searchResultsCountRenderingModel = new CustomSearchResultsCountRenderingModel();
this.FillBaseProperties(searchResultsCountRenderingModel);
searchResultsCountRenderingModel.JsonDataProperties = this.GetJsonDataProperties();
searchResultsCountRenderingModel.ResultsCountTextFieldName = "ResultsCountText";
searchResultsCountRenderingModel.ShowingResultsForTextFieldName = "ShowingResultsForText";
return searchResultsCountRenderingModel;
}
Add a new config patch to register your repo.
You also need a new razor file that is a copy of ..\Views\ResultsCount\Results Count.cshtml
Finally, Update the related JS file from the base theme to count for your new added element, you can find it in this location: /sitecore/media library/Base Themes/SearchTheme/Scripts/component-search-results-count
, you simply can download that, edit it, and then add it to your unicorn or tds tracking.
Following is Sitecore doc. for how you can create a custom SXA rendering:
https://doc.sitecore.com/developers/sxa/93/sitecore-experience-accelerator/en/walkthrough--building-a-simple-rendering.html