Last active
April 15, 2017 09:54
-
-
Save matthewkenny/bad6e2ad020b8079c1d022d176045cf8 to your computer and use it in GitHub Desktop.
Blog - When Personalisation Breaks Rendering Parameters - Code
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
<?xml version="1.0"?> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> | |
<sitecore> | |
<pipelines> | |
<mvc.customizeRendering> | |
<processor type="Sitecore.Mvc.Analytics.Pipelines.Response.CustomizeRendering.Personalize, Sitecore.Mvc.Analytics" | |
set:type="MyNamespace.ResetParametersOnSubstitutedRenderings, MyAssembly" /> | |
</mvc.customizeRendering> | |
</pipelines> | |
</sitecore> | |
</configuration> |
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
public class ResetParametersOnSubstitutedRenderings : Personalize | |
{ | |
protected override void ApplyChanges(Rendering rendering, RenderingReference reference) | |
{ | |
// If the rendering being applied is different from the original renderings | |
if (!rendering.RenderingItem.ID.Equals(reference.RenderingItem.ID)) | |
{ | |
// Fetch the default rendering parameters for the new rendering | |
rendering.Parameters = new RenderingParameters(reference.RenderingItem.Parameters); | |
} | |
// Continue to apply the built-in changes | |
base.ApplyChanges(rendering, reference); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment