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

How to create a controller js

HarishDv
Level 3
Level 3

Hi Guys ,

There are some Js files in libs , such as the preferences.js (/libs/cq/security/widgets/source/widgets/security/Preferences.js).

I copied the same file to my apps folder and when i instantiate some variables (My_Prop = "new prop") , it can be accessed from anywhere (any other JS file).

I dont want to disturb the preferences.js . I want to create my own js similar to this so that when i declare some properties , it shall be available anywhere and accessed from every other js file.

 

Thanks in advance

Harish

1 Accepted Solution
Ojjis
Correct answer by
Level 7
Level 7

Hi Harish,
Either, you can just create these JS files and include them to your ClientLib. Then make sure that they have the correct categories and dependencies so that they will be included at the right point. After that they can be used from your other files in your code.

If that is not enough and you really need them to be included at an earlier stage, you can create those files and make sure that a js.txt file will include your script files somewhere else. There are loads of these and you have to check when and where those files are included so you wont run into any problems.

Good Luck
/Johan

View solution in original post

1 Reply
Ojjis
Correct answer by
Level 7
Level 7

Hi Harish,
Either, you can just create these JS files and include them to your ClientLib. Then make sure that they have the correct categories and dependencies so that they will be included at the right point. After that they can be used from your other files in your code.

If that is not enough and you really need them to be included at an earlier stage, you can create those files and make sure that a js.txt file will include your script files somewhere else. There are loads of these and you have to check when and where those files are included so you wont run into any problems.

Good Luck
/Johan

View solution in original post