When putting a custom component inside an experience fragment, wcmmode.edit is false even in authoring mode. | Community
Skip to main content
Level 2
April 11, 2023
Solved

When putting a custom component inside an experience fragment, wcmmode.edit is false even in authoring mode.

  • April 11, 2023
  • 1 reply
  • 815 views

I have a custom component whose htl template uses wcmmode.edit to conditionally render content.

 

When outside of an experience fragment, the wcmmode.edit works. But when I put it inside an experience fragment and link to the XF from a page, wcmmode.edit always resolves to false.

 

Am I using experience fragment incorrectly or something? Should experience fragment be only static content. Otherwise, how can I get the wcmmode.edit to work properly? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sady_Rifat

Hello @alanng4 ,
${wcmmode.edit}" option is true when you are in edit mode. When you are editing the experience fragment that property will return true as you are expecting.
But when you are using in a page or iParsys the inner content is actually disabled and not in edit mode. 
That means you can not detect Author/Publish mode using slightly.

If you must need to detect it then you can take the help of Sling Model Class.

@Inject private SlingSettingsService slingSettingsService; boolean isAuthor = slingSettingsService.getRunModes().contains("author"); // Proper Getter and Setter // Use in HTL

 

1 reply

Sady_Rifat
Community Advisor
Sady_RifatCommunity AdvisorAccepted solution
Community Advisor
April 11, 2023

Hello @alanng4 ,
${wcmmode.edit}" option is true when you are in edit mode. When you are editing the experience fragment that property will return true as you are expecting.
But when you are using in a page or iParsys the inner content is actually disabled and not in edit mode. 
That means you can not detect Author/Publish mode using slightly.

If you must need to detect it then you can take the help of Sling Model Class.

@Inject private SlingSettingsService slingSettingsService; boolean isAuthor = slingSettingsService.getRunModes().contains("author"); // Proper Getter and Setter // Use in HTL