12

What is the difference between Sitecore.Context.PageMode.IsExperienceEditor and Sitecore.Context.PageMode.IsExperienceEditorEditing? I've always used Sitecore.Context.PageMode.IsExperienceEditor in my code, but I've noticed that some frameworks such as Glass Mapper use Sitecore.Context.PageMode.IsExperienceEditorEditing.

Sitecore.Context.PageMode.IsExperienceEditorEditing sounds like it would only return true when in the Experience Editor and Edit Mode is enabled, or when Editing is turned on under the view tab; however, I've found that Sitecore.Context.PageMode.IsExperienceEditorEditing always returns the same value as Sitecore.Context.PageMode.IsExperienceEditor.

10

Actually, it's relatively straight forward. IsExperienceEditorEditing is false when you're editing a component - but editing it via Edit Related Item.

I've added a bit of code to Default Sublayout.ascx to demonstrate.

.IsExperienceEditor: <%= Sitecore.Context.PageMode.IsExperienceEditor %><br />
.IsExperienceEditorEditing: <%= Sitecore.Context.PageMode.IsExperienceEditorEditing %><br />

enter image description here

I then go...

enter image description here

And Sitecore opens up like this.

enter image description here

I think you're meant to use this to render your content "normally" when IsExperienceEditorEditing is false like this - and render it "context aware" when it's not.

7

IsExperienceEditorEditing requires few more checks to be true to return true as well. Still in 99% of the standard Sitecore work you can use any of them:

  /// <summary>
  /// Gets a value indicating whether this instance is experience editor.
  /// </summary>
  /// <value>
  ///   <c>true</c> if this instance is experience editor; otherwise, <c>false</c>.
  /// </value>
  public static bool IsExperienceEditor
  {
    get
    {
      return Context.Site.DisplayMode == DisplayMode.Edit;
    }
  }

  /// <summary>
  /// Gets a value indicating whether this instance is experience editor editing.
  /// </summary>
  /// <value>
  ///   <c>true</c> if this instance is experience editor editing; otherwise, <c>false</c>.
  /// </value>
  public static bool IsExperienceEditorEditing
  {
    get
    {
      SiteContext site = Context.Site;
      if (site == null 
            || WebUtil.GetCookieBool(site.GetCookieKey("sc_navigate"), false) 
            || (!Context.PageMode.IsExperienceEditor 
            || !(WebUtil.GetQueryString("sc_ce") != "1")))
        return false;
      return WebUtil.GetQueryString("sc_webedit") != "0";
    }
  }
  • 6
    What are those extra checks for? When do they make a difference? – Dmytro Shevchenko Oct 24 '16 at 20:17
  • 2
    That's a really good question @DmytroShevchenko. There were a questions about it long time ago, when the property was still called IsPageEditorEditing. The explanation was The user is inline editing in the Page Editor. I'm not sure if it says anything extra. You can see the question asked on Sitecore Community site here community.sitecore.net/developers/f/8/t/1782 – Marek Musielak Oct 24 '16 at 21:52
2

The IsExperienceEditorEditing flag indicates that the user is actively engaged in changing the Item being edited (either the Item, the Presenatation Details, or one of the Datasource Items on page). There are good reasons to take advantage of this feature:

Show Renderings that Hide if they are Empty

IsExperienceEditorEditing becomes very useful if you have Rendering behavior where a null DataSource causes the Rendering to be hidden. - You can have the otherwise missing Rendering display in the Editor only when it needs to be seen to be edited/moved, etc.

Assist Content Authors with Difficult Renderings

I have also seen people add help text, or modify the markup of the Rendering in this mode to make it easier to edit - A perfect example would be a slide carousel that normally presents one slide at a time, but in IsExperienceEditorEditing it renders alternative markup that allows for all slides to be seen on page, making it easier to select slide components for editing, or adding new slides, etc.

  • 2
    I have not been able to make IsExperienceEditor and IsExperienceEditorEditing return different values. Once I add ?sc_mode=edit to the URL, both turn to true and stay that way as long as I am in editing mode. Could you please specify in which situations there will be an actual difference between the values of these properties? – Dmytro Shevchenko Oct 25 '16 at 14:39
  • 2
    Without building a quick test, I would suggest that if a user was attempting to edit a page that was read-only for some reason (workflow, language, locked) IsExperienceEditor should be true due to the rendered toolbar, but IsExperienceEditorEditing should be false, because the page is read-only. You'll need to be a non-admin to test this. – Sergeant Sitecore Oct 25 '16 at 14:50
  • 2
    If it's true, then there is indeed an important difference between the two properties. Once you know this for sure, could you please include that in your answer? That would be very useful to know. – Dmytro Shevchenko Oct 25 '16 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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