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);
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;
}
}
}