Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

How to get the path of page

Avatar

Level 7

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 7

In HTL there is implicit object in sightly 

${currentPage.path}

View solution in original post

2 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 7

In HTL there is implicit object in sightly 

${currentPage.path}