Skip to main content
Level 4
Jan 14, 2025 4:58 PM UTC
Solved

Get HTML of Experience Fragment programatically within Java?

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>" }
arunpatidar
arunpatidarAccepted solution
Community Advisor
Jan 15, 2025 7:51 AM UTC

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

3 replies

MukeshYadav_
Community Advisor
Community Advisor
Jan 14, 2025 5:12 PM UTC

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

Translate
Level 4
Jan 14, 2025 6:14 PM UTC

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.

Translate
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
Jan 15, 2025 7:51 AM UTC

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

Translate
Arun Patidar