Skip to main content
2 of 2
added 20 characters in body; edited tags; edited title
Marek Musielak
  • 24.2k
  • 3
  • 31
  • 64

Sitecore.Mvc.Analytics 10.3 doesn't contain a definition for Sitecore.Mvc.Analytics.Pipelines.Response.CustomizeRendering

using Sitecore.Data.Items;
using Sitecore.Mvc.Analytics.Pipelines.Response.CustomizeRendering;
using Sitecore.Pipelines;
using Sitecore.Pipelines.ResolveRenderingDatasource;

public class CustomMVCResolveRenderingDataSource : CustomizeRenderingProcessor
{
    public override void Process(CustomizeRenderingArgs args)
    {
        var rendering = args.Rendering;
        //Get the Site Item
        var contextSiteItem = GetSiteItem(Context.Item);

        if (!string.IsNullOrEmpty(rendering.DataSource) && contextSiteItem != null)
        {
            if (rendering.DataSource.Contains("$SiteName"))
            {
                rendering.DataSource = rendering.DataSource.Replace("$SiteName", contextSiteItem.Name);
                Item sourceItem = Context.Database.GetItem(rendering.DataSource);
                if (sourceItem != null)
                {
                    rendering.DataSource = sourceItem.ID.ToString();
                }
            }
        }
        //Initialize the resolved DataSource to ResolveRenderingDatasourceArgs
        var renderingDSArgs = new ResolveRenderingDatasourceArgs(rendering.DataSource);
        CorePipeline.Run("resolveRenderingDatasource", renderingDSArgs);
        rendering.DataSource = renderingDSArgs.Datasource;
    }
}