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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

osgi config to javascript

Avatar

Level 4

How to Fetch OSGI configurations value in JavaScript ?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@karthick1356,

There are two ways.

1. OSGI configuration data in Sightly, where your JavaScript will pickup configuration from there. An example implementation can be found here https://sourcedcode.com/blog/aem/with-htl-pass-data-from-aem-backend-to-javascript

2. OSGI configuration data via Sling Servlet. You can create a servlet that can be utilized by the JavaScript business logic. An Ajax request should be sufficient to obtain the OSGI configuration data.

View solution in original post

6 Replies

Avatar

Community Advisor

You need to read in your component html from sling model and keep it in hidden field and then use it in javascript.

Avatar

Community Advisor

Hi @karthick1356,

 

To fetch the OSGI Values, first read them in HTML from Java via data attribute and in JS you can initialize the module and access it.

 

Find my related answer here

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

Avatar

Level 4
Hi KiranVedantam1992, Do you know straight forward way like using sling.getService?

Avatar

Correct answer by
Community Advisor

@karthick1356,

There are two ways.

1. OSGI configuration data in Sightly, where your JavaScript will pickup configuration from there. An example implementation can be found here https://sourcedcode.com/blog/aem/with-htl-pass-data-from-aem-backend-to-javascript

2. OSGI configuration data via Sling Servlet. You can create a servlet that can be utilized by the JavaScript business logic. An Ajax request should be sufficient to obtain the OSGI configuration data.