0

I'm trying to get all datasources of a rendering, including personalization.

As we are using SXA the datasource strings look like this: local:/Data/Test
What is the best way to get the item from this? Normally the getRenderingDatasource pipeline would handle this, but how do I do this programmatically?

  • Once you have this information, how might you make use of it? – Michael West Jan 7 at 16:56
2

It's quite easy:

//inject pipeline manager (instead of ServiceLocator you can use constructor injection if needed)
BaseCorePipelineManager pipelineManager = ServiceLocator.ServiceProvider.GetService<BaseCorePipelineManager>();

//create pipeline arguments where you put data source string
var args = new ResolveRenderingDatasourceArgs(rendering.DataSource);

//run the pipeline
pipelineManager.Run("resolveRenderingDatasource", args);

As an output, you will have either ID or an item path in args.Datasource property.

  • Thanks, this helped me a lot :) But I had to do it this way (although having the correct usings): ServiceLocator.ServiceProvider.GetService(typeof(BaseCorePipelineManager)) as BaseCorePipelineManager – Lars-Pascal Körber Jan 8 at 13:32
  • Just such using using Microsoft.Extensions.DependencyInjection; and you will be able to use GetService like that: ServiceLocator.ServiceProvider.GetService<BaseCorePipelineManager>(). – Dawid Rutkowski Jan 8 at 14:53
  • You will need to add Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.DependencyInjection.Abstractions nuget packages for this. – Dawid Rutkowski Jan 8 at 14:54
  • I added the first dll, but not the Abstractions one. That explains it. Thanks! – Lars-Pascal Körber Jan 9 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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