Skip navigation
Currently Being Moderated

CQ5 image gallery component

Jan 9, 2013 2:46 AM

Tags: #cq5.5



I'm a newbee in CQ5. I need to create an image gallery similar to How can I proceed towards that?


I was thinking of taking a DAM folder path from the content author as an input and using that I would create the block by iterating all the images contained within that folder. Is that a correct way? If so, what API I can use to iterate through the image files contained in a DAM folder?


Any help or response is highly appretiated.



  • Currently Being Moderated
    Jan 13, 2013 5:22 PM   in reply to suvasishm

    Assuming resource pointing to /content/dam/myproject/photo_gallery  something like below should work


    Iterator<Resource> assetList=resolver.listChildren(resource);

            while (assetList.hasNext()) {

                Resource child =;

                Asset asset = child.adaptTo(Asset.class);

                 if (asset != null) {




    Mark as:
  • Currently Being Moderated
    Feb 5, 2013 4:02 PM   in reply to suvasishm

    Hi suvsm, now that you have the child node (the image in the DAM), what is the subsequent code to display the image.


    And did the image display properly on the publisher?




    Mark as:
  • Currently Being Moderated
    Feb 6, 2013 10:57 AM   in reply to Sham HC

    Hi Sham - I followed this style ofiginally too but I could not get the image to display.

    Can you fill in the ... in your post, please?


    my code below doesn't seem to work:


    if (asset != null) {

    Image myImage = new Image(asset or resource - you named it child)


    image.draw(out);  //this doesn't work



    and even just using the image.getSrc() in my image tag,


    <ima src="<%=image.getSrc()%>/>


    will not work properly if my the path to the DAM, /content/dam/* is blocked on the publisher.

    Mark as:
  • Currently Being Moderated
    Feb 6, 2013 10:45 AM   in reply to suvasishm

    Hi suvsm!  Thanks for replying!


    I've done the same code too...which helps confirms that I'm not going crazy and my approach isn't totally wrong.


    But if this works for you then you also know that the path to your DAM, "/content/dam/hnodemo/photo_gallery", is open to the world on your publisher, right?




    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points