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

SOLVED

How to get home page in sling model

hptarora
Level 2
Level 2

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

1 Accepted Solution
Umesh_Thakur
Correct answer by
Community Advisor
Community Advisor

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

 

 

View solution in original post

2 Replies
asutosh_jena
Community Advisor
Community Advisor

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!

Umesh_Thakur
Correct answer by
Community Advisor
Community Advisor

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

 

 

View solution in original post