How to get the path of page | Community
Skip to main content
Level 6
November 24, 2021
Solved

How to get the path of page

  • November 24, 2021
  • 2 replies
  • 1511 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ronnie09

In HTL there is implicit object in sightly 

${currentPage.path}

2 replies

Siva_Sogalapalli
Community Advisor
Community Advisor
November 24, 2021

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();
}

}
Ronnie09AuthorAccepted solution
Level 6
November 24, 2021

In HTL there is implicit object in sightly 

${currentPage.path}