Storing output (<div>) of component into String instead of rendering it
Hi all,
Hi all,
Hi Jorg,
Some solution i found and thought sharing with you all. Let me know if you see any drawback of this approach.
Got a little solution for this after some digging. Sharing for everyone's benefit. Please let me know if you see any drawbacks of this solution.
There is a new attribute called "var" introduced in sling 1.3 taglibs. This attribute stores the final output of a component.
Apache Sling - Sling Scripting JSP Taglib
CQ 5.6.1 has sling tablib 1.0 so you will need to upload version sling taglib jar 1.3. You can download same from below link
http://repo1.maven.org/maven2/
You can just upload via felix console. Below is forum discussion around same
jsp - Using Sling Taglib version 1.3 in a CQ5.6.1 project - Stack Overflow
Now in yor JSP you will have to include this new taglib
<%@taglib prefix="sling1" uri="http://sling.apache.org/
and then do the <sling:include> with "var" attribute
<sling1:include path="/etc/designs/mysite/jcr:
and then you can read the "var" using pageContext
(String)pageContext.
Remember CQ5.6.1 uses sling taglib version 1.0 so if you include /lib/foundation/global.jsp (which has version 1.0 then it will conflict ) then it will conflict.
Below is complete JSP code
------------------------------
<%@ page import="org.apache.sling.
<%@ page import="org.apache.sling.
<%@taglib prefix="sling1" uri="http://sling.apache.org/
<sling1:defineObjects />
<%
response.setContentType("
%>
<sling1:include path="/etc/designs/mysite/jcr:
<%
response.setContentType("
JSONWriter writer = new JSONWriter(response.getWriter(
writer.object();
writer.key("header");
writer.value((String)
writer.endObject();
%>
==============================
copy paste from documentation page
==============================
Includes a resource rendering into the current page.
==============================
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.