Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.
SOLVED

Get HTML of Experience Fragment programatically within Java?

Avatar

Level 5

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>"
}
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @dylanmccurry 

Please check this if help

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/get-the-xf-page-source-cod...

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

plain selector may not return the html but text

Arun Patidar

AEM LinksLinkedIn

View solution in original post

3 Replies

Avatar

Community Advisor

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

Avatar

Level 5

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.

Avatar

Correct answer by
Community Advisor

Hi @dylanmccurry 

Please check this if help

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/get-the-xf-page-source-cod...

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

plain selector may not return the html but text

Arun Patidar

AEM LinksLinkedIn