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.
Solved! Go to Solution.
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
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.
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
Thanks kautuksahni & smacdonald2008
Views
Replies
Total Likes