how to get currentPage object in javascript, as javascript file resides in clientlibs folder of the component. please give me example code snippets.

Avatar

Avatar
Validate 1
Level 1
karthick1356
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
karthick1356
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile
karthick1356
Level 1

24-03-2021

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

207 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

207 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

24-03-2021

Hi @karthick1356 

When you say you want currentPage object in JS which is inside your clientlib, for what purpose you need it? You will not be able to get the currentPage object in JS as the context will not be avilable on clientside and it's either available on HTL or Java which is on server side.


If you can provide the use case we can come with a concrete answer.

 

Thanks!

Answers (2)

Answers (2)

Avatar

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

195 likes

Total Posts

213 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

195 likes

Total Posts

213 posts

Correct reply

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

24-03-2021

Hi @karthick1356,

 

you can use Javascript USE API to get all the values you need.

 

Sample code:

use(function () {
    var Constants = {
        DESCRIPTION_PROP: "jcr:description",
        DESCRIPTION_LENGTH: 50
    };

    var title = currentPage.getNavigationTitle() || currentPage.getTitle() || currentPage.getName();
    var description = properties.get(Constants.DESCRIPTION_PROP, "").substr(0, Constants.DESCRIPTION_LENGTH);

    return {
        title: title,
        description: description
    };
});

Reference page: https://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/use-api-javascript.html?lan...

 

Hope this helps.

 

Thanks,

Kiran Vedantam

Avatar

Avatar
Validate 1
Level 6
Bhuwan_B
Level 6

Likes

133 likes

Total Posts

125 posts

Correct reply

50 solutions
Top badges earned
Validate 1
Affirm 50
Give Back 5
Boost 100
Give Back 3
View profile

Avatar
Validate 1
Level 6
Bhuwan_B
Level 6

Likes

133 likes

Total Posts

125 posts

Correct reply

50 solutions
Top badges earned
Validate 1
Affirm 50
Give Back 5
Boost 100
Give Back 3
View profile
Bhuwan_B
Level 6

24-03-2021