Created
January 22, 2019 20:16
-
-
Save techknowhow/9ae0c1c0e720454f221b31ebec8e3c10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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