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.
-
have you checked out the answers in tridion.stackexchange.com/questions/3450/… and tridion.stackexchange.com/questions/2171/… ?– Bart KoopmanCommented Apr 10, 2014 at 12:24
-
Thats about knowing CM-side - I am talking about working out in the staging website if the HTTP request is coming from Experience Manager– Will PriceCommented Apr 10, 2014 at 12:26
-
This one perhaps tridion.stackexchange.com/questions/2489/…– Bart KoopmanCommented Apr 10, 2014 at 12:26
-
Thanks Bart - I missed that. Unfortunately no definitive answer there though...– Will PriceCommented Apr 10, 2014 at 12:36
-
Indeed I couldn't find my answer in the ADF and reverted to using JavaScript instead, which I gather is not going to work in your case.– Bart KoopmanCommented Apr 10, 2014 at 13:05
2 Answers
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 {
$.removeCookie("test");
}
});
})(jQuery);
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 Commented 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. Commented Apr 10, 2014 at 12:56
-
1Would 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 (addingXpmDevice/[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. Commented Apr 10, 2014 at 13:13 -
I have submitted this as an idea on ideas.sdltridion.com Commented Apr 10, 2014 at 14:26
-