Expand my Community achievements bar.

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

Avatar

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

Avatar

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.

Avatar

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;

        }