1

I have a module that uses ajax to post back to the server for data. Some of this data is configurable while in experience editor. Users are winding up in a state with this module where experience editor html is showing up while in normal mode. The steps to get to this are as follows

  1. The user visits the page with the module in normal mode
  2. The user then opens a different tab/window in the same browser and opens experience editor mode
  3. The user then goes back to the original tab and clicks one of the buttons that makes an ajax call. The resulting rendered fields are rendered for experience editor and that excess html is rendered as plain text

Currently to work around this I added a flag on a data attribute called data-enforce-normal-mode. When that is set to true I pass along that flag with my ajax response. I then wrap my original code in the following which causes the html to render as though it wasn't in experience editor mode:

//enforceNormal is passed in to the controller through javascript
if (enforceNormal)
{
    using (new UserSwitcher(Sitecore.Security.Accounts.User.FromName("sitecore\\anonymous", false)))
    {
        //get object to return which contains field values which should 
        //be editable in experience editor mode
    }
}

This feels like a hack. A longer routed alternative is to pass the enforce bool to the service which gets my return object and use the field renderer with disable-web-editing=true for every field when the bool is set to true but that sounds tedious and hard to maintain in the future due to any new editable field needing this pattern. Is there a better way to maintain the state that my page is in so that if a page is accessed by a user that isn't logged in the ajax request will have the correct context for this?

  • What is reason to use normal and edit modes in same time? Is it possible to use different browsers for it?(or your browser + browser in incognito mode) – Anton Nov 17 '17 at 12:56
  • @Anton there isn't. I know that they can do that but it's popping up for editors while they are on a content management server once in a while and they want to address it through coding rather than making it a training issue. – Teeknow Nov 17 '17 at 16:05
  • @Teeknow you can check if the user is on the experience editor. If so, you disabled the editing. – Hishaam Namooya Nov 18 '17 at 15:51
  • @Teeknow Do you need popup window with normal mode that is opening in Experience Editor? I think that you don't. Wrap code that call popup window with check if it is EE mode, e.g: community.sitecore.net/technical_blogs/b/sitecoremartina_blog/… – Anton Nov 19 '17 at 17:48

Your Answer

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

Browse other questions tagged or ask your own question.