Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

How to access a SlingServlet from Serverside JavaScript

Avatar

Level 3

Hi everyone,

I wrote a SlingServlet  at @SlingServlet(resourceTypes = "/apps/global-components/left-nav", selectors = "breadcrumb", extensions = "data")

It is just returning a JSON object that is a list of page paths.

What is the best way to access this SlingServlet from Serverside JavaScript? or from HTL?

I want to render the data doing something like this in HTL:

<div data-sly-use.breadcrumbs="breadcrumb.js">

     <div data-sly-list.path="${breadcrumbs.breadcrumbs}">

          <div>${path}</div>

     </div>

</div>

1 Accepted Solution

Avatar

Correct answer by
Level 10

One option you have to invoke this from HTL is to use AJAX - then when you get back the data - you can populate HTML:

Adobe Experience Manager Help | Creating an AEM HTML Template Language Component that posts data usi...

Use a GET operation.

Another option - if you want to use HTL to get data from Java - write a class that uses WCMUsePojo instead of a Servlet.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

One option you have to invoke this from HTL is to use AJAX - then when you get back the data - you can populate HTML:

Adobe Experience Manager Help | Creating an AEM HTML Template Language Component that posts data usi...

Use a GET operation.

Another option - if you want to use HTL to get data from Java - write a class that uses WCMUsePojo instead of a Servlet.