Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Edit mode on Page for Experience fragements Header

Avatar

Community Advisor

Hi All,

I want to get the edit mode of the page for a header which is an Experience fragment.

I am trying ${wcmmode.edit}, but every time I am getting false in the author URL.

Can anyone help me here how can I get the edit mode of the page in the Header.

Thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

This code worked for me.
If you have experience fragment and want to check wcmmode on non-experience fragment page and you want to make everything work properly in edit mode, with ?wcmmode=disabled and without ?wcmmode( Live Url), then - 

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
}
return decodeURI(dc.substring(begin + prefix.length, end));
}

var myCookie = getCookie("wcmmode");
var params = window.location.search;

if( myCookie=='preview' || params=='?wcmmode=disabled' || myCookie==null){
// DISABLE MODE
}

 

View solution in original post

4 Replies

Avatar

Community Advisor

@Prince_Shivhare 

I think the wcm mode is determined based on cookie, can you check what is in the cookie?

For such scenarios is it ok for you to use following condition ? (in case the goal is to determine if the page is loaded on author mode and not publish) 

${wcmmode.edit || wcmmode.preview}

 

Avatar

Community Advisor

you can try changing the WCM mode based on the condition

e.g.

Changes the WCM mode:

 

 

 

Edit Mode
<header data-sly-resource="${'path/to/resource' @ wcmmode='edit'}"></header>
Other Mode
<header data-sly-resource="${'path/to/resource' @ wcmmode='disabled'}"></header>

e.g.
<header data-sly-resource="${'path/to/resource' @ wcmmode=wcmmode.edit?'edit':'disabled'}"></header>

 

 



Arun Patidar

Avatar

Correct answer by
Community Advisor

This code worked for me.
If you have experience fragment and want to check wcmmode on non-experience fragment page and you want to make everything work properly in edit mode, with ?wcmmode=disabled and without ?wcmmode( Live Url), then - 

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
}
return decodeURI(dc.substring(begin + prefix.length, end));
}

var myCookie = getCookie("wcmmode");
var params = window.location.search;

if( myCookie=='preview' || params=='?wcmmode=disabled' || myCookie==null){
// DISABLE MODE
}