Question

What is the difference between

 1. <c:import url="layout-link.jsp" />
 2. <sling:include path="layout-link.jsp" />
 3. <cq:include script="layout-link.jsp" />

What is the advantage of each tag? When should each be used?

Answer, Resolution

1. <c:import url="layout-link.jsp" />

I assume this is the import tag of the Standard Tag Library. This tag is documented at http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/c/import.html and does not know about Sling directly.

But -- asuming -- this tag is using a RequestDispatcher to dispatch the request, this tag will also pass Sling and the Sling resource resolver.

2. <sling:include path="layout-link.jsp" />

This is the include tag of the Sling JSP Tag library. This tag knows about Sling and also supports RequestDispatcherOptions.

3. <cq:include script="layout-link.jsp" />

This tag is Communiqué specific extension of the Sling JSP Tag library include tag. IIRC it supports callings scripts in addition to just including renderings of resources.

What is the advantage of each tag? When should each be used?

In a Communiqué application, I would suggest to generally use the Communiqué or Sling include tag since this provides you more Sling support.

You may use the JSTL import tag if you don't have specific requirements for Sling extended features, plan to use the JSP (fragment) outside of Communiqué or if you want to further process the generated (imported) content with a reader or a variable.

In the future, it is conceivable that the Sling and/or Communique tag library will also provide an import tag similar to the JSTL import tag to be able to further process the imported result.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy