1

I have a search results page where I am using the Results Count rendering. I know that it has There are {count} results as a rendering parameter - but if there are no results then my search results is outputting No results and the results count is showing There are 0 results, so I don't want to show the results count message in this instance.

I cannot see anything obvious on the Model that I could check if the Count equalled 0.

@model Sitecore.XA.Feature.Search.Models.SearchResultsCountRenderingModel

<div @Html.Sxa().Component(Model.Rendering.RenderingCssClass ?? "search-results-count", Model.Attributes) data-properties='@Model.JsonDataProperties'>
    <div class="component-content">
        @Model.MessageIsEmpty
        <div class="results-count">
            @Html.Sxa().Field(Model.FieldName, Model.DataSourceItem, !Model.IsControlEditable)
        </div>
        <div class="progress"></div>
    </div>
</div>

1 Answer 1

2

Most of the SXA search renderings have their logic on the front-end side - in JavaScript. Repositories are uses in most cases only to send data and configuration to the client side so that scripts could do rest of the things.

In the case or Results Count rendering you would need to take a look at component-search-results-count.js (this file belongs to Search base theme - /sitecore/media library/Base Themes/SearchTheme/Scripts/component-search-results-count). Inside of it, you will find a backbone SearchResultCountView view where is a statement which is listening for results-loaded SXA search event. Modify this part to something like that:

XA.component.search.vent.on("results-loaded", function (data) {
    if (data.dataCount > 0) {
        resultsCountContainer.html(inst.resultsCountText.replace('{count}', data.dataCount));
        inst.$el.find(".results-count").show();
    }
}); 

This if statement will show label only when there will be any results.

Keep in mind that this file will get overridden when you will upgrade SXA. So either you will remember about it or you would like to override this file in your theme.

1
  • Ah that's where the logic was hiding - thanks :)
    – Jen
    Commented May 13, 2019 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.