1

I am trying to index rendered content. I am using the following plugin.

It works with a global data source, however, it does not index rendered content if the data source is local (local:/Data/Rich Text). I traced down the piece of code that is failing. When Sitecore retrieves the Item's renderings via the Visualization.GetRenderings it returns an empty string in the DataSource property of the result.

Is this a known issue? Also, am I doing this right? Meaning is there a better way to index data connected to a page via a rendering data source?

Some more context:

When I step through the code I can see the DataSource is an empty string:

Empty Data Source showing it not working

However, I do see the data source on the item:

Local data source image

Here it is coming through with the id when I use a direct link:

Direct link showing it working

1
  • 1
    @markcassidy While this issue was discovered using the Sitecore.IndexRenderedContent Plugin I believe this issue will occur whenever you attempt to use Sitecore.Data.Items.Item.Visualization.GetRenderings(DeviceItem device) method. Jul 12, 2021 at 15:48

2 Answers 2

1

I don't know how Sitecore.IndexRenderedContent plugin is exactly working but it's definitely not aware of the SXA local data sources (and probably about page relative data sources too). Try to resolve them manually:

if (YOUR_DATA_SOURCE.StartsWith(Sitecore.XA.Foundation.LocalDatasources.Constants.PageRelativePrefix, StringComparison.InvariantCultureIgnoreCase) || YOUR_DATA_SOURCE.StartsWith(Sitecore.XA.Foundation.LocalDatasources.Constants.LocalPrefix, StringComparison.InvariantCultureIgnoreCase))
{               
    RESOLVED_DATA_SOURCE = Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetService<ILocalDatasourceService>().ExpandPageRelativePath(YOUR_DATA_SOURCE, CONTEXT_ITEM.Paths.FullPath);
}
3
  • The problem here is that the data source of the rendering is coming back as a empty string when it should be local:/Data/Rich Text 1. So I cannot resolve the data source. Aug 2, 2021 at 22:46
  • @NikolaKramaric The ILocalDatasourceService service is returning an empty string? Aug 3, 2021 at 9:26
  • This line var renderings = args.IndexedItem.Visualization.GetRenderings(args.DeviceItem, false); returns an empty string in the data sources for the renderings that have a local:* data source. Same issue as this post: sitecore.stackexchange.com/questions/29387/… that you answered. I don't have enough reputation to comment, but the problem I have is that YOUR_DATA_ROURCE_STRING is empty even though it does have a value in Sitecore. Aug 3, 2021 at 12:28
1

Sitecore was able to get back to me with a response on my ticket:

We have tested this with some sample code something like the following:

Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");

Sitecore.Data.Items.Item test = master.GetItem("/sitecore/content/MyTenant/MySite/Home/Test");

Sitecore.Data.Items.DeviceItem device = Sitecore.Context.Device;

var renderings = test.Visualization.GetRenderings(device,false);

Running only this, we are able to see the same issue as you have described, however, if we then set the current context item with the following

[...]

Sitecore.Data.Items.DeviceItem device = Sitecore.Context.Device;

Sitecore.Context.Item = test;

var renderings = test.Visualization.GetRenderings(device,false);

We are then unable to reproduce the described issue. As mentioned in this doc, "In presentation and other components, processing often begins with the context item".

TL;DR - Set Sitecore.Context.Item = item prior to running your GetRenderings code and it works!

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.