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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

How to get the path of page

Avatar

Level 6

I am trying to get the path of page where the component is currently rendering. Currently my component is in experiece fragment, but I want the path of page where it is rendering.

 

PageManager pageManager=resourceResolver.adaptTo(PageManager.class);
        Page currentPage = pageManager.getContainingPage(resource);
        String pagePath = currentPage.getPath();

 

pagePath is giving me the path of experience fragment I cant get the path of page where it is loading.

1 Accepted Solution

Avatar

Correct answer by
Level 6

In HTL there is implicit object in sightly 

${currentPage.path}

0 Replies

Avatar

Community Advisor

Hi @Ronnie09 

Please try this:

 

 
@Model(adaptables = {Resource.class })
Public class Model{

@Inject
private Page currentPage;

private String pagePath;

@PostConstruct
protected void init() {
log.debug("** Start of sling Model **");
pagePath = currentPage.getPath();
}

}

Avatar

Correct answer by
Level 6

In HTL there is implicit object in sightly 

${currentPage.path}