Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Get runmodes value for client-side JS using hidden field

Avatar

Avatar
Validate 10
Level 2
fionas76543059
Level 2

Likes

3 likes

Total Posts

69 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 10
Level 2
fionas76543059
Level 2

Likes

3 likes

Total Posts

69 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Applaud 5
View profile
fionas76543059
Level 2

08-01-2021

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/get-runmodes-value-in-clie...

 

Hi folks,

There is a discussion here on using a hidden field to make the "runmode" available to client-side JS widgets. I want to do the same as the OP.

Jorg Hoh said

"You should not expose the concept of runmodes to your frontend. Instead you should define a marker which is queried by your frontend; and this marker might be rendered directly into the page or queried via JSON. And the presence of the marker in the markup (or JSON) is controlled by an OSGI configuration which can be set via runmode-based OSGI configuration.

Otherwise you need to have knowledge in your frontend about backend specifics."

 

Just looking for clarification on the 1st point made, does Jorg mean to derive a value from the runmode and put that on the page ?

 

thanks

Fiona

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

190 likes

Total Posts

199 posts

Correct Reply

60 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

190 likes

Total Posts

199 posts

Correct Reply

60 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile
KiranVedantam1992
Level 7

08-01-2021

Hi @fionas76543059,

 

For fetching the run modes, you can use SlingSettingsService.

 

Code:

@Reference
private SlingSettingsService slingSettingsService;

private Boolean isPublish;

private boolean isPublish() {
return this.slingSettingsService.getRunModes().contains("publish");
}

 

You can now expose this boolean in HTL like this:

${classObject.isPublish}

This resultant object value can be consumed by the Front end as mentioned here

 

As per my understanding what Jorg Hoh is trying to say is to separate the business logic and presentation logic.

 

Thanks,

Kiran Vedantam.

Answers (1)

Answers (1)

Avatar

Avatar
Validate 10
MVP
kunal23
MVP

Likes

166 likes

Total Posts

565 posts

Correct Reply

172 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 50
View profile

Avatar
Validate 10
MVP
kunal23
MVP

Likes

166 likes

Total Posts

565 posts

Correct Reply

172 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 50
View profile
kunal23
MVP

08-01-2021

Yes it is indeed best practice to abstract this run mode concept and not expose it in your front end logic. And for abstraction you can set a data attribute in your HTML and the value of which can be set based on an OSGI Configuration. The OSGI configs are read based on the runmodes automatically by the system. 

So you just have to keep different values of the data attribute in OSGI configuration for each run mode. The system will return you the value based on the current AEM running mode and thereby you don't have to worry about run modes in your front end code.