Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to get home page in sling model

Avatar

Level 3

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

Avatar

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

Avatar

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!

Avatar

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