Expand my Community achievements bar.

SOLVED

How to create a controller js

Avatar

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

Avatar

Correct answer by
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

Avatar

Correct answer by
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