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

SOLVED

How to get the path of page

Avatar

Level 5

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 5

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 5

In HTL there is implicit object in sightly 

${currentPage.path}