Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

AEM get livecopy path from js-use-api (HTL JavaScript)

ridhos17946705
Level 1
Level 1

Hello,
I have a question about js-use-api (HTL JavaScript)


I have a page called product/en/index.html, in this page I want to get livecopy path from spesific path.

I already have the livecopy page, here is the detail:

Blueprint Page : /content/project/product/en/help.html

Livecopy Page : /content/project/product/uk/contact/help.html

Let's say I have the blueprint path, how can I get the livecopy path of that blueprint using HTL JavaScript?

I have try below code but not working,

"use strict";

use(function () {

    var data = {}

    var thePage = "/content/project/product/en/help";

    data.livecopyPath = currentPage.getLiveCopy(thePage).getPath();

    return data;

});

Please help

4 Replies
smacdonald2008
Level 10
Level 10

I do not think you can use JS to get this type of information - you would need to use the Strongly types API:

"The Adobe AEM Quickstart and Web Application."

So to hook this API into an HTL component - you should use SLing Model - not JS HTL.

ridhos17946705
Level 1
Level 1

thanks smacdonald2008​, sorry for late reply

I have been reserach and as smacdonald2008​ say in doc "The Adobe AEM Quickstart and Web Application." 

we use this code and it's worked

request.resourceResolver.adaptTo(Packages.com.day.cq.wcm.msm.api.LiveRelationshipManager) and get via function getLiveRelationships(resour,null,null)

var the_page = "live-copy-path";

    var resour = resource.getResourceResolver().getResource(the_page);

var livecopy = request.resourceResolver.adaptTo(Packages.com.day.cq.wcm.msm.api.LiveRelationshipManager).getLiveRelationships(resour,null,null);

      while (livecopy.hasNext()) {

            var page = livecopy.next();

            data.blueprint = page.getTargetPath();

            break;

        }