Expand my Community achievements bar.

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>"
}
2 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.