May 20, 2020
Estimated Post Reading Time ~

Adobe CQ Renders Pages with Custom Extension

You may already know CQ can render HTML pages with .html extension, I'd like to show you how to tell CQ to render pages with another custom extension. For example, instead of responding to http requests end with .html, we want CQ to respond to requests end with .foo.

In order to tell CQ to be able to deal with a custom request with a special page extension (e.g., .foo), you need to

Implement a component JSP file to render the page with .foo extension, and

Tell CQ that .foo extension is acceptable.

Here's the details of what you need to do:

#1) Implement component JSP to render page with .foo extension
Like many other CQ5 component, you should have known how to implement a CQ5 component in JSP, and what to name (according to url-to-script resolution rules) it so that it'll be used to render the page being requested. In our example case to render page with .foo extension, the JSP component can be named as foo.jsp. If you're not familiar with url-to-script resolution in Sling, please refer to other articles and tutorials first then come back to this article. In this post, I'd like to focus on the next step which is essential and is not quite clearly documented by Adobe.

#2) Tell CQ that .foo extension is acceptable
This has to be achieved by creating a file under /libs/foundation/components/primary/cq/Page/. Specifically, using our .foo extension example, we need to create the following file named Page.foo.jsp if you want request to pages of .foo extension to be acceptable by CQ:

/libs/foundation/components/primary/cq/Page/Page.foo.jsp

Make the above file has the following one line content:

<%@include file="/libs/foundation/components/primary/cq/Page/proxy.jsp" %>

Please note, for unknown reason, use the following line without the full path of proxy.jsp or with extra return characters at the end may lead you to some unknown 500 Error on rendering the page, so don't:

<%@include file="proxy.jsp" %>
[return]

Therefore, I highly suggest you to make sure you don't have extra carriage return at the end and use the full path to reference proxy.jsp in Page.foo.jsp if possible. Otherwise, you may encounter 500 Internal Server Error as I did using CQ 5.6.1.

Conclusion
Suppose you have implemented a component JSP named foo.jsp (#1) and have a Page.foo.jsp file set up as mentioned above (#2), as a result, user request to http://...whatever/..../[pagename].foo will be handled by proxy.jsp, which in terms will somehow pass the control to the component jsp file named foo.jsp referenced by the resourceType (or resourceSuperType) property of the page's content node.

References
CQ5.3: How to add a custom page extension
How to create custom renderers for all/specific extensions?


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.