resource object in sightly | Community
Skip to main content
ramanareddy438
October 16, 2015
Solved

resource object in sightly

  • October 16, 2015
  • 3 replies
  • 4982 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Feike_Visser1

This works for me...

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

3 replies

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

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

ramanareddy438
October 16, 2015

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.

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

This works for me...

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