Skip to content

Instantly share code, notes, and snippets.

@techknowhow
Created January 22, 2019 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techknowhow/9ae0c1c0e720454f221b31ebec8e3c10 to your computer and use it in GitHub Desktop.
Save techknowhow/9ae0c1c0e720454f221b31ebec8e3c10 to your computer and use it in GitHub Desktop.
using Sitecore.Mvc.Pipelines.Response.RenderRendering;
using Sitecore.Mvc.Presentation;
namespace Sitecore.Foundation.Multisite.Pipelines
{
public class ResolveRenderingContext : EnterRenderingContext
{
protected override void EnterContext(Rendering rendering, RenderRenderingArgs args)
{
//Make your changes to the items that are used to build the context here
if (args.PageContext != null &&
args.PageContext.Item != null &&
(args.Rendering.DataSource.Contains("query")))
{
var innerQuery = args.Rendering.DataSource.Replace("query:", "");
var datasourceItem= Context.Item.Axes.SelectSingleItem(innerQuery);
//replacing the datasource with Item Id of the queried item
if (datasourceItem != null)
args.Rendering.DataSource = datasourceItem.ID.ToString();
else
Sitecore.Diagnostics.Log.Error("Resolving Rendering Context >> " + args.Rendering.DataSource + " Not Found", this);
}
//build the context using the existing functionality
base.EnterContext(rendering, args);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment