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

Ronnie09
Level 4
Level 4

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
Ronnie09
Correct answer by
Level 4
Level 4

In HTL there is implicit object in sightly 

${currentPage.path}

View solution in original post

2 Replies
SivaPrasadReddyS
Level 8
Level 8

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

}
Ronnie09
Correct answer by
Level 4
Level 4

In HTL there is implicit object in sightly 

${currentPage.path}

View solution in original post