How to convert/export the AEM page into an experience fragment?

Avatar

Avatar
Give Back
Level 2
vijays80591732
Level 2

Likes

6 likes

Total Posts

56 posts

Correct reply

4 solutions
Top badges earned
Give Back
Ignite 1
Validate 1
Boost 5
Boost 3
View profile

Avatar
Give Back
Level 2
vijays80591732
Level 2

Likes

6 likes

Total Posts

56 posts

Correct reply

4 solutions
Top badges earned
Give Back
Ignite 1
Validate 1
Boost 5
Boost 3
View profile
vijays80591732
Level 2

08-04-2021

Hi,

 

Is there a way to render the entire AEM page in an experience fragment? 

 

USE CASE:

 I have a homepage that contains around 10 components. Now, I want to create a replica of the home page in the experience fragment and export it to AT. Since most of my components are tightly coupled and I cannot use the components directly in experience fragment. So, I'm looking for something that will bring the entire HTML DOM for the homepage and render in experience fragment via some custom component. I have tried the below servlet, but I'm getting an internal server error.

 

 

import org.apache.felix.scr.annotations.Reference;

import org.apache.felix.scr.annotations.sling.SlingServlet;

 

import org.apache.sling.api.SlingHttpServletRequest;

import org.apache.sling.api.SlingHttpServletResponse;

import org.apache.sling.api.servlets.SlingSafeMethodsServlet;

import org.apache.sling.engine.SlingRequestProcessor;

 

import com.day.cq.contentsync.handler.util.RequestResponseFactory;

import com.day.cq.wcm.api.WCMMode;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

 

@SlingServlet(paths={"/bin/customservlet”})

public class AemResourceResolutionServlet extends SlingSafeMethodsServlet {

 

    protected final Logger log = LoggerFactory.getLogger(this.getClass());

 

    @Reference

    private RequestResponseFactory requestResponseFactory;

 

    @Reference

    private SlingRequestProcessor requestProcessor;

 

    @Override

    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

 

 

        String requestPath = "/content/myapp/en/us_en/home";

 

        HttpServletRequest req = requestResponseFactory.createRequest("GET", requestPath);

        log.debug("req..{}", req.getPathInfo());

        WCMMode.DISABLED.toRequest(req);

 

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        HttpServletResponse resp = requestResponseFactory.createResponse(out);

        requestProcessor.processRequest(req, resp, request.getResourceResolver());

    }

}

 

@Vijayalakshmi_S  @Veena_Vikram @Anudeep_Garnepudi @arunpatidar26 @Jörg_Hoh @vanegi 

 

Regards,

Vijay

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

127 likes

Total Posts

192 posts

Correct reply

81 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

127 likes

Total Posts

192 posts

Correct reply

81 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile
rush_pawan
Level 7

08-04-2021

Hello,

 

Here is couple of options you can try based on your need

 

1. if your home page components are authored inside container like layout/grid or similar then you can convert to experience fragment directly from page.

rush_pawan_0-1617903470643.png

 

But, that will change the content from home to experience fragment now as it will be referenced to experience fragments created. but also do this

        - configure AT cloud service configuration

        - configure OOTB experience fragment template or if you use custom experience frag template to support your component design to display correct when access as experience fragment page, to view correctly going forward for authors

       - configure replication agent for this experience fragment template

       - export it to AT and deliver to home page as exp frag content

      pretty much refer - https://experienceleague.adobe.com/docs/experience-manager-64/authoring/authoring/experience-fragmen...  and https://experienceleague.adobe.com/docs/experience-manager-64/administering/integration/experience-f...

 

this will be long sustaining approach

 

2. else, simple but short term way is to create path to experience frag content after converting them via creating path to actual content similar as Anudeep mentioned earlier

 

Thanks!!

 

Answers (1)

Answers (1)

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

08-04-2021

@vijays80591732 

Directly hit page(/content/myapp/en/us_en/home.html) from front-end(AJAX) and you will get entire page html as response. You can request for child nodes also(/content/myapp/en/us_en/home/_jcr_content/root/...../xyz.html).