Skip to content

Instantly share code, notes, and snippets.

@5up3rman
Created June 29, 2017 19:22
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 5up3rman/5d1bafecabb68dbeb928461abb651e07 to your computer and use it in GitHub Desktop.
Save 5up3rman/5d1bafecabb68dbeb928461abb651e07 to your computer and use it in GitHub Desktop.
AddWrapper Example
using Sitecore;
using Sitecore.Mvc.ExperienceEditor.Presentation;
using Sitecore.Mvc.Pipelines.Response.RenderRendering;
using Sitecore.Mvc.Presentation;
namespace EditorEnhancementToolkit.Foundation.ContentEditor.Pipelines.RenderRenderer
{
public class AddWrapper : Sitecore.Mvc.ExperienceEditor.Pipelines.Response.RenderRendering.AddWrapper
{
public override void Process(RenderRenderingArgs args)
{
if (Context.Site == null || !Context.PageMode.IsExperienceEditorEditing || !args.Rendering.RenderingType.Equals("Layout"))
return;
var marker = GetMarker(args.Rendering);
if (marker == null)
{
base.Process(args);
return;
}
var index = args.Disposables.FindIndex(x => x.GetType() == typeof (Wrapper));
if (index < 0)
index = 0;
args.Disposables.Insert(index, new Wrapper(args.Writer, marker));
}
protected IMarker GetMarker(Rendering rendering)
{
return new RenderingMarker(RenderingContext.Current, rendering.RenderingItem.DisplayName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment