I want to only render XPM Page/Region/CP/Field markup if the request for the page is coming from Experience Manager (so not when browsing the staging or live sites). Is there some way of using the ADF/API to detect this? I had a look at ADF claims and cookies but they seem to be the same regardless of whether I am in XPM or on staging.


2 Answers 2


In the past I have used JavaScript (jquery) to figure out whether or not I'm presently in XPM in order to tweak html to make it present better while in XPM and ease editing quirks.

In your question you mentioned looking in the cookies for this information. Maybe you could use a combined JS/cookie approach.

This is simple food for thought snippet is using the jquery-cookie plugin. This could work so long as your site is not utilizing iFrames. Since XPM wraps your page in an iFrame while it is active. This snippet will see that the location doesn't match that of the parent indicating you are in an iFrame and XPM is active.

It will do the check to see if you're running in an iFrame and set or delete a cookie appropriately. You could then check for that cookie in your page and make the choice of whether or not to render the XPM markup.

(function($) {
$(function() {
    var isInIframe = (window.location != window.parent.location) ? true : false;
    if (isInIframe) {
        $.cookie("test", 1);
    } else {

The most reliable way is to only output the markup if publishing to a target that should have XPM. So you should clear the "Enable for inline editing" checkbox on any Publication Targets that you do not want to use XPM on (i.e. live ones).

  • I am rendering the markup CD-side, but want to output the markup on staging only if the request is coming from XPM
    – Will Price
    Apr 10, 2014 at 12:26
  • I think you're gonna have a bad time with that. AFAIK there is no reliable way to detect that (would apparently make a good ER though). Hence why I suggest that you do it during publishing instead. Either that or always output it on staging, but not on live - perhaps controlled by the URL or configuration settings. Apr 10, 2014 at 12:56
  • 1
    Would be useful if SDL would set an X-SDL-Experience-Manager header in the request when they load the Page in XPM. @WillPrice I have modified the User Agent strings for the Device Preview (adding XpmDevice/[device name] to it) so that I could defer from there it was the Device Preview from XPM, but you don't have that option for the normal Desktop View. Apr 10, 2014 at 13:13
  • I have submitted this as an idea on ideas.sdltridion.com
    – Will Price
    Apr 10, 2014 at 14:26
  • I will add it to the backlog...
    – Nuno Linhares
    Apr 10, 2014 at 17:45

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.