Skip to main content
aleksandrsp9196
Level 2
Apr 27, 2017 8:36 AM UTC
Solved

Sightly component with drag and drop image (get the file reference)

<sly data-sly-resource="${'mainImg' @resourceType='wcm/foundation/components/image'}" />
Question: I want to use drag-and-drop image (html5smartimage) component in Edit Mode only and to fetch the link to the image file (./fileReference ) and use it as a css/background-image for a div.

while I edited it I decided I can do it with "use" function...

In other words: how to get access to the html5smartimage's dialog from "use" function

P.s By the way, why there isn't exist such a tag "Sightly" on this forum?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
leeaslingAccepted solution
Level 8
May 5, 2017 6:01 PM UTC
public class ImageHelper extends WCMUsePojo { public String getImageSrc() { Image image = new Image(this.getResource(), "image"); if (image != null && image.hasContent()) { image.setSelector("img"); return image.getSrc(); } return null; } public String getBackgroundImageSrc() { return "background-image:url(" + this.getImageSrc() + ")"; } }
<div data-sly-use.img="${'package.name.ImageHelper'}" style="${img.backgroundImageSrc @ context='styleString'}"> Some stuff in here. </div>

5 replies

kautuk_sahni
Level 9
May 5, 2017 9:59 AM UTC

<sly data-sly-resource="${'mainImg' @resourceType='wcm/foundation/components/image'}" />
Question: I want to use drag-and-drop image (html5smartimage) component in Edit Mode only and to fetch the link to the image file (./fileReference ) and use it as a css/background-image for a div.

while I edited it I decided I can do it with "use" function...

In other words: how to get access to the html5smartimage's dialog from "use" function

P.s By the way, why there isn't exist such a tag "Sightly" on this forum?

Translate
Kautuk Sahni
leeaslingAccepted solution
Level 8
May 5, 2017 6:01 PM UTC
public class ImageHelper extends WCMUsePojo { public String getImageSrc() { Image image = new Image(this.getResource(), "image"); if (image != null && image.hasContent()) { image.setSelector("img"); return image.getSrc(); } return null; } public String getBackgroundImageSrc() { return "background-image:url(" + this.getImageSrc() + ")"; } }
<div data-sly-use.img="${'package.name.ImageHelper'}" style="${img.backgroundImageSrc @ context='styleString'}"> Some stuff in here. </div>
Translate
Feike_Visser1
Adobe Employee
Adobe Employee
May 7, 2017 8:00 AM UTC

Also the the core-component implementation here: https://github.com/Adobe-Marketing-Cloud/aem-core-wcm-components/tree/master/content/src/content/jcr_root/apps/core/wcm/components/image/v1/image

I'd be careful using the fileReference-property directly, you might reference a large asset to the client.

Translate
smacdonald2008
Level 10
May 7, 2017 2:58 PM UTC

We will have a HELPX artilce out soon that shows Core Components and image as well. 

Translate
aleksandrsp9196
Level 2
May 8, 2017 8:22 AM UTC

Thank you for reply. This is a good news!
If it's possible could you write an article with an example how to get access to properties of nested components from USE-API please. It will be very helpful.

- parsys
     - customComponent
             - logic.js
         - html5smartimage
            - Dialog
        - text
           - Dialog

Translate