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

How to get home page in sling model

Avatar

Avatar
Boost 1
Level 1
hptarora
Level 1

Like

1 like

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Validate 1
View profile

Avatar
Boost 1
Level 1
hptarora
Level 1

Like

1 like

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Validate 1
View profile
hptarora
Level 1

09-05-2021

Hi,

 

I have a component which I am including in base page body.

 

In sling model of the component, how can I get if the current page is Home page or not.

 

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
MVP
Umesh_Thakur
MVP

Likes

147 likes

Total Posts

157 posts

Correct Reply

53 solutions
Top badges earned
Validate 1
Applaud 25
Ignite 3
Ignite 1
Give Back 5
View profile

Avatar
Validate 1
MVP
Umesh_Thakur
MVP

Likes

147 likes

Total Posts

157 posts

Correct Reply

53 solutions
Top badges earned
Validate 1
Applaud 25
Ignite 3
Ignite 1
Give Back 5
View profile
Umesh_Thakur
MVP

10-05-2021

Hi @hptarora,

Can you check once for Context aware configuration available in your application ?

if yes you can take help from context aware config to get the homepage if there is one for the same, if not then you can easily add one for homepage path.

this is very normal implementation in almost all multilingual application.

Hope this will help.

Umesh Thakur

 

 

Answers (1)

Answers (1)

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

576 likes

Total Posts

687 posts

Correct Reply

199 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

576 likes

Total Posts

687 posts

Correct Reply

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

09-05-2021

Hi @hptarora 

 

You can define a page property(let's say homePage) where you can author the home page link. Let's say your home page is /content/something/en_us/index

 

Now your page node contains homePage=/content/something/en_us/index value in crx.

 

Now in you sling model you can read the homePage property value and can compare with currentPage object which is OOTB and available with @ScriptVariable annotation.

Put a condition if homePage = currentPage.getPath() then you are on Home page else you are on other pages.

@ScriptVariable
private Page currentPage;

@ValueMapValue
private String homePage;
if (StringUtils.isNoneEmpty(currentPage.getPath(), homePage) && StringUtils.equalsIgnoreCase(currentPage.getPath(), homePage)) {
// Home page
}

 

Thanks!