You know how it’s super easy to change how a rendering is rendered based on
Sitecore.Context.PageMode? If you’ve ever wished there was a similar check available for
PageMode.IsIndexCrawlerCrawling, then read on.
- If you have renderings that show alerts to front-end users (for example, cookie consent or legal disclaimers), it makes sense not to render these at crawl time since their HTML shouldn’t show up in search results.
- If you have dynamic renderings that AJAX their content, you may want to provide a static version for the index.
- If you have renderings that inject user tracking code, it makes sense to keep this code out of the indexed version of the page.
By default, Coveo uses the
HtmlContentInBodyWithRequestsProcessor class to index a page’s content. This class makes an HTTP request to the page’s URI and indexes the HTML that is returned. Unfortunately,
HtmlContentInBodyWithRequestsProcessor is mostly non-virtual and private methods, so it’s difficult to customize. But we can get around this by creating a wrapper.
Replace default processor with custom processor in configuration
Now we just need to make our renderings aware of whether the special query string parameter is present. Add this
IsCrawl property to your Rendering Model class. You can test for this property in your View and change rendering output accordingly.
public bool IsIndexCrawler => Sitecore.Context.Request.QueryString["isIndexCrawl"] == "1";