2

I would like to show some message in my component in case this component was just added in the Experience Editor, but the item is not saved yet.

Is there any way to do it?

1 Answer 1

2

You can do this by checking if the current rendering is contained in the list of renderings of the current item.

@{
    Guid currentRenderingId =
        Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.UniqueId;

    DeviceItem device = Sitecore.Context.Device;
    RenderingReference[] renderings =
        Sitecore.Context.Item.Visualization.GetRenderings(device, true);

    bool renderingIsSaved =
        renderings.Any(
            r => new Guid(r.UniqueId) == currentRenderingId);
}

@if (renderingIsSaved == false)
{
    <div class="unsaved-rendering">
        This rendering is not saved yet.
    </div>
}

The above example is for MVC; the code should be similar in case you use WebForms.

3
  • thanks, seems like no standard API, need to add it to extensions class Commented Apr 4, 2017 at 13:10
  • @Arbejdsglæde That's a good idea. Also, to prevent performance degradation, I would wrap the code above into the following check: if(Sitecore.Context.PageMode.IsExperienceEditor) { ... }. Commented Apr 4, 2017 at 13:20
  • it goes without saying Commented Apr 4, 2017 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.