Issue getting current page path in a nested experience fragment | Community
Skip to main content
Level 2
April 2, 2024
Solved

Issue getting current page path in a nested experience fragment

  • April 2, 2024
  • 3 replies
  • 1558 views

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!

Best answer by Anudeep_Garnepudi

@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 - 606189

3 replies

TarunKumar
Community Advisor
Community Advisor
April 2, 2024

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

cmanoha1Author
Level 2
April 2, 2024

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.

Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
April 2, 2024

@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 - 606189

November 27, 2024

this is also giving xf path itself

November 21, 2025

Hi @vidyaav2 How did you resolve this ? Could you please let me know. And why the wrong answers are marked as corrected its not a good practice.

arunpatidar
Community Advisor
Community Advisor
April 8, 2024

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