Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

resource object in sightly

Avatar

Level 2

Hi All,

How to use resource object in sightly html file. I have to get fileReference parameter from the resource object. Please help on this.

 

Best regards

M. Ramana Reddy

1 Accepted Solution

Avatar

Correct answer by
Employee

This works for me...

<div data-sly-list="${resource.listChildren}">
    <div>${item.path} ${item.sling:resourceType}</div>
</div>

View solution in original post

3 Replies

Avatar

Employee

you can do ${properties.fileReference} to get the value.

Avatar

Level 2

Feike Visser wrote...

you can do ${properties.fileReference} to get the value.

 

I am printing the properties object in sightly. It doesn't show fileReference in that object. I am using a html5smartimage in the dialog and I want to display that image in the sightly page using the fileReference property. I thought of getting the image resource from the builtin "resource" object as I have seen an example of the same but using JSP.

http://experience-aem.blogspot.in/2013/12/aem-cq-56-adding-images-in-multifield.html

As shown in the above link they are getting the Images from the resource object. I would like to do the same in sightly.

<%@include file="/libs/foundation/global.jsp"%> <%@ page import="java.util.Iterator" %> <%@ page import="com.day.cq.wcm.foundation.Image" %> <%@ page import="org.apache.sling.commons.json.JSONArray" %> <% Iterator<Resource> children = resource.listChildren(); if(!children.hasNext()){ %> Configure Images <% }else{ Resource imagesResource = children.next(); ValueMap map = imagesResource.adaptTo(ValueMap.class); String order = map.get("order", String.class); Image img = null; String src = null; JSONArray array = new JSONArray(order); for(int i = 0; i < array.length(); i++){ img = new Image(resource); img.setItemName(Image.PN_REFERENCE, "imageReference"); img.setSuffix(String.valueOf(array.get(i))); img.setSelector("img"); src = img.getSrc(); %> <img src='<%=src%>'/> <% } } %>

For getting fileReference from resource object do I have to set in the resource object somewhere in the java or any other??

Please Help me on this.

Avatar

Correct answer by
Employee

This works for me...

<div data-sly-list="${resource.listChildren}">
    <div>${item.path} ${item.sling:resourceType}</div>
</div>