Search code examples
aemsightly

Using adapters in JavaScript Use-API in Sightly


I have a path and want to adapt it into Page using Sightly.

The user can enter a path in the dialog — in my logic, I am using currentPage as a default value, but if the user enters a path, I want to use this instead.

How can I change the path into a Page object in JavaScript, in order to use all functions of the Page API? (i.e. I'm using JavaScript for my backing logic rather than Java)


Solution

  • The PageManager is implicitly available as a pre-defined object in the JavaScript Use-API (pageManager), that you can go ahead & use.

    E.g, if you had a variable path, and wanted to resolve the relevant page & return its title, you could do:

    use(function () {
        var path ="/content/foo/bar";
        return {
            pageTitle: pageManager.getPage(path).title
        };
    });