3 Replies Latest reply on Mar 27, 2013 8:17 AM by lufecir28

    How to render image from page properties

    lufecir28

      Hello,

       

      I am using CQ 5.6.

       

      I have a problem rendering the image you can set in the page properties of a page. I use the same code to render that image as I do for images in my other components, but the image is not being rendered.

      So I investigated the content structure and I noticed that the image nodes in the page do not have a 'sling:resourceType' set, while image nodes from for example the 'image' or 'textImage' component have this property set to 'foundation/components/image'.

       

      If I manually add the property 'sling:resourceType' with value 'foundation/components/image' to the image nodes in page properties, they are rendered fine.

       

      So my questions are:

      *) Is this different structure for the image nodes intended?

      *) What can I do to have a 'sling:resourceType' property added to the image nodes from page properties? I have tried adding a cq:editConfig to my page components where this property has been specified, but that did not make a difference.

       

      I have been struggling with this for a while now, so any ideas would be welcome.

       

      Kind regards,

       

      Luc Feys

        • 1. Re: How to render image from page properties
          Panasaki

          Hi Luc,

           

          If you see the foundation carousel component, that retrieves the images of the pages included in the dialog, you can recover the image in the next way:

           

          // currently we just check if "image" resource is present

          Resource r = page.getContentResource("image");

          if (r != null) {

              Image image = new Image(r);

              img = page.getPath() + ".img.png" + image.getSuffix();

          }

           

          If you want the image of the page where you are, change page for currentPage.

           

          With the object Image you can draw with image.draw() and with img is the string to include in a html img src.

           

          I hope this information would be helpful.

          1 person found this helpful
          • 2. Re: How to render image from page properties
            lufecir28 Level 1

            Hi Panaski,

             

            Thank you. Your answer got me in the right direction. I just had to make one addition, since sometimes I had images as embedded files in the page properties (in that case your suggestion worked fine) and in other cases I had images from the dam (in which case I had to stick to the functionality I was using before).

             

            Cheers,

             

            Luc

            • 3. Re: How to render image from page properties
              lufecir28 Level 1

              Hi,

               

              I have an additional question, regarding the images of a page. As stated above, rendering them works fine. But now I would also like to have them resized within certain boundaries. Is there a way to define the min/max width/height in the design of the page component for these images?

              I tried adding a node (name='image', jcr:primaryType=nt:unstructured) to /etc/designs/<myproject>/jcr:content/<mypagecomponent>. I then added minHeight, minWidth, maxHeight, ... properties to that node, but it seems they are not being picked up by the img.png.java servlet from the libs/foundation/page component.

              I created this design node based on a similar node which was added in the design of <mypagecomponent> for an 'image' in a 'par' when I changed the design of it.

               

              So I'm wondering if it is at all possible to define a design for the image of a page and if it, how I should do it.

               

              Kind regards,

               

              Luc