Get HTML of Experience Fragment programatically within Java? | Community
Skip to main content
Level 4
January 14, 2025
Solved

Get HTML of Experience Fragment programatically within Java?

  • January 14, 2025
  • 2 replies
  • 668 views

Hi all,

 

I am building an API which will serve up some HTML for other websites to consume. The general idea is that there will be an experience fragment within AEM, and my API will grab the HTML output of this experience fragment and append that to the API response.

 

Is there a way within Java that I can programmatically calculate the rendered HTML output of an experience fragment? The fragment will be made up of multiple sightly based components.

 

Imagine an API response similar to this:

 

{ "cssLink": "mysite.com/path/to/some.css", "jsLink": "mysite.com/path/to/some.js", "html": "<div class='my-fragment'>...</div>" }
Best answer by arunpatidar

Hi @dylanmccurry 

Please check this if help

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/get-the-xf-page-source-code-in-java/td-p/617498

use content selector to get HTML without head and other tags.

plain selector may not return the html but text

2 replies

MukeshYadav_
Community Advisor
Community Advisor
January 14, 2025

Hi @dylanmccurry ,

You may directly get the html content with .plain.html  i.e, selector plain and extension html

You can use like

{ "cssLink": "mysite.com/path/to/some.css", "jsLink": "mysite.com/path/to/some.js", "html": "/experience-fragment-path.plain.html" }

Thanks

Level 4
January 14, 2025

Yeah... I am aware of this mechanism, but I am working on replacing another API which returns the raw html directly.

To minimize impact on dependent services, I am hoping to just recreate the exact signature of the API call.

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
January 15, 2025

Hi @dylanmccurry 

Please check this if help

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/get-the-xf-page-source-code-in-java/td-p/617498

use content selector to get HTML without head and other tags.

plain selector may not return the html but text

Arun Patidar