3

Using Sitecore 9.1, SXA 1.8.1. I have a page with a link list clone. When I delete a link from that list and then publish via workflow the deletion is not propogated properly through to the web database.

So I thought I could iterate over the datasources and ensure those are published correctly.

When I get access to the renderings of Workflow Test page it's datasource is a string like:

local:/Data/Promo Banner here

enter image description here

Is there a smart SXA way of easily getting a reference to that item?

This is only when you choose to create the datasource under the local data folder. If you instead point the SXA datasource at an item in the centralised data folder then it has an id as expected.

1 Answer 1

3

In order to resolve such data sources you need to run resolveRenderingDatasource pieline and it should do the job for you. Take a look at this:

// don't need to use ServiceLocator, you can also use constructor injection to injects pipeline manager
BaseCorePipelineManager pipelineManager = ServiceLocator.ServiceProvider.GetService<BaseCorePipelineManager>();
ResolveRenderingDatasourceArgs args = new ResolveRenderingDatasourceArgs("YOUR_DATA_SOURCE_STRING_HERE");
pipelineManager.Run("resolveRenderingDatasource", args);

After this args.Datasource can be an ID or a path (it also can be empty if the data source won't be resolved).

Depending on the place where you will run this code there might be some problems with accessing current context site or item. You might need to run SiteContextSwitcher like this:

ResolveRenderingDatasourceArgs args = new ResolveRenderingDatasourceArgs("YOUR_DATA_SOURCE_STRING_HERE");
SiteInfo siteInfo = ServiceLocator.ServiceProvider.GetService<ISiteInfoResolver>().GetSiteInfo(CONTEXT_ITEM);
using (new SiteContextSwitcher(new SiteContext(siteInfo)))
{
    pipelineManager.Run("resolveRenderingDatasource", args);
}
3
  • Hi, I'm probably confused what this is doing for me. If I use "local:/Data/Promo Banner here" the args.DataSource is still just returning "local:/Data/Promo Banner here". I was hoping it would resolve to a more usable path or id. Otherwise it still seems like I need to code to detect "local:" and replace with the current item's path. Did I miss the point of doing this or perhaps I've messed up the implementation code :)
    – Jen
    Commented Jun 28, 2019 at 0:09
  • It should convert local:/... to path or ID. Did you try to use a version with SiteContextSwither? If yes are you sure that you have correct context item (the item which belongs to your site)? Commented Jun 28, 2019 at 6:54
  • Yes I tried using the SiteContextSwitcher and it didn't resolve the local into something useful - so have just written my own logic to get the path of the page and replace local with that \ data.
    – Jen
    Commented Jul 15, 2019 at 1:06

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.