JSON Renderer for Sightly Templates | Community
Skip to main content
New Participant
February 1, 2018
Solved

JSON Renderer for Sightly Templates

  • February 1, 2018
  • 3 replies
  • 1439 views

Hi All,

I'm trying to create a JSON renderer for a sightly template and it should output a json content when page is requested with <pagename>.<selector>.json.

Currently its working only when it is invoked this way <pagename>/jcr:content.<selector>.json

I have done this previously on CQ5.5 with the same approached mentioned in the following thread.

Provide alternative JSON renderer? Without losing default JSON renderer?

Can someone pls advise on how to achieve the same functionality for a sightly template?

Note: I'm able to achieve the expected results by creating a servlet with resourcetype binding. However, I'm curious to understand why the renderer approach isnt working.

Regards,

Lingesh P.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kautuk_sahni

You can create a Sling Servlet and bind it with the resourceType of your basepage component (assuming you already have basepage component for all page components) along with resourceType binding, you can also specify your custom selector (like .infinity) and extension as .JSON.

Doing so, now using your servlet, you can create any JSON response that you need.

Refer to following link to know more about binding servlet to resourcetype - https://sling.apache.org/documentation/the-sling-engine/servlets.html#example-registration -by-resource-type-etc

Reference 1:- Adobe Experience Manager Help | Binding Adobe Experience Manager Servlets to ResourceTypes

Also, have a look at Pageinfo.Json:- Obtaining Page Information in JSON Format

3 replies

LingeshPAuthor
New Participant
February 13, 2018
kautuk_sahni
kautuk_sahniAccepted solution
Employee
February 12, 2018

You can create a Sling Servlet and bind it with the resourceType of your basepage component (assuming you already have basepage component for all page components) along with resourceType binding, you can also specify your custom selector (like .infinity) and extension as .JSON.

Doing so, now using your servlet, you can create any JSON response that you need.

Refer to following link to know more about binding servlet to resourcetype - https://sling.apache.org/documentation/the-sling-engine/servlets.html#example-registration -by-resource-type-etc

Reference 1:- Adobe Experience Manager Help | Binding Adobe Experience Manager Servlets to ResourceTypes

Also, have a look at Pageinfo.Json:- Obtaining Page Information in JSON Format

Kautuk Sahni
smacdonald2008
New Participant
February 1, 2018

Most of the Core components use resource binding. I believe using resource binding and having the HTL component  use a servlet is the best way to proceed here.  Its a better way then using URL selectors.