Expand my Community achievements bar.

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

Issue getting current page path in a nested experience fragment

Avatar

Level 2

Hi,

 

We have a use-case in a component, where we're using nested experience fragments on a page and when I try to get the current page path in a component (nested inside the innermost XF), the get the path of it's parent XF. 

 

For example, we have two XFs - Child XF (/content/experience-fragment/project/child-xf) and Parent XF (/content/experience-fragment/project/parent-xf). And a Test Page (/content/project/test-page), where Parent XF is being rendered via 'Experience Fragment' component.

 

Now, in Parent XF, the condition to render Child XF is checkbox controlled. And the component used in Parent XF is a react-based component, which will make a simple GET request to Child XF path and render the response HTML on the page. This is leading to the component inside Child XF consider the Parent XF as it's current page. As in, injecting current page in the inner-most component is giving path as '/content/experience-fragment/project/child-xf' instead of '/content/project/test-page'.

 

We have another use-case, involving Building Blocks, which is working out well for us in fetching current path details. Not sure, what went wrong in the above implementation.

 

Any leads in debugging the issue is appreciated. Thanks!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@cmanoha1 

 

Try below snippet.

String pagePath = request.getPathInfo().replace(".html", "");
Resource pageResource = resourceResolver.getResource(pagePath);

 

Solved: Re: Unable to get current Page Path in cloud publi... - Adobe Experience League Community - ...

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @cmanoha1 ,

If you are not able to access the current page path in HTL then try to get it through your custom logic in model class.
Then use this model class in sightly to retrieve the current Page path.


Thanks
Tarun

Avatar

Level 2

Hi @TarunKumar 

We have the same implementation. Getting the Page currentPage in sling model. We're getting XF path instead of current actual page path.

Avatar

Correct answer by
Community Advisor

@cmanoha1 

 

Try below snippet.

String pagePath = request.getPathInfo().replace(".html", "");
Resource pageResource = resourceResolver.getResource(pagePath);

 

Solved: Re: Unable to get current Page Path in cloud publi... - Adobe Experience League Community - ...

Avatar

Community Advisor

Hi @cmanoha1 

Were the user suggestions helpful? Let us know if more details are needed or mark the answer as correct. If you found a solution independently, please share it with the community.



Arun Patidar