Update Component Depending on WCMMode in Angular | Community
Skip to main content
evancooperman-s
Level 2
Mar 20, 2020 3:44 PM UTC
Solved

Update Component Depending on WCMMode in Angular

For various components we use, we have different output depending on whether the author is in edit mode or preview mode (or wcmmode is disabled altogether).  Is there an easy way to hook into this, such that we can leverage it when outputting content in an Angular template...and such that when it changes, we re-render the component?

 

I used the latest SPA archetype to generate my Angular project.

 

Thanks in advance!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
BrianKasingli
BrianKasingliAccepted solution
New Participant
Mar 22, 2020 3:22 PM UTC

@evancooperman-s 

You can pass a property to your AngularJS component named "mode". The "mode" property can be set with either your Sling Models or pass the value directly with Sightly.

 

Sling Model: @SlingObject private SlingHttpServletRequest request; WCMMode.fromRequest(request); Sightly: data-sly-test="${wcmmode.edit}" data-sly-test="${wcmmode.preview}" data-sly-test="${wcmmode.disabled}" data-sly-test="${wcmmode.design}"

 

I hope this helps. 

2 replies

BrianKasingli
BrianKasingliAccepted solution
New Participant
Mar 22, 2020 3:22 PM UTC

@evancooperman-s 

You can pass a property to your AngularJS component named "mode". The "mode" property can be set with either your Sling Models or pass the value directly with Sightly.

 

Sling Model: @SlingObject private SlingHttpServletRequest request; WCMMode.fromRequest(request); Sightly: data-sly-test="${wcmmode.edit}" data-sly-test="${wcmmode.preview}" data-sly-test="${wcmmode.disabled}" data-sly-test="${wcmmode.design}"

 

I hope this helps. 

Translate
BaluM
Level 2
Mar 21, 2020 10:15 AM UTC

Hi,

AEM will create a cookie with name "wcmmode = (edit/preview)" if your page is opened in edit mode.

 

// Fetch cookie value and compare 
if (cookieValue === 'edit') {

//customcode
} else{

//customecode

}

 

Cookie in edit mode:

 

Cokkie in preview mode:

 

 

Translate