Expand my Community achievements bar.

Join expert-led, customer-led sessions on Adobe Experience Manager Assets on August 20th at our Skill Exchange.
SOLVED

Adding a background image for component using sightly

Avatar

Level 1

Hi, 

I would like to add a background image to my component. I've tried these two - they don't work. Please help with the correct syntax.

 
            <p> Background Color : ${heroProps.iconImage.imagePath}</p>
            <p style="backgroundImage:${heroProps.iconImage.imagePath@ context='styleToken'};"> Text : ${heroProps.iconImage.imagePath}
            </p>
        
 
 <div class="fnd-hero-eyebrow-title" data-sly-test="${heroProps.title != ''}"
             style="background-image:url(${heroProps.iconImage.imagePath@ context='styleToken'});">
            ${heroProps.title @ context='html'}
        </div>
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Tahera_BegumSh 

Try with below uri context

style="background-image: url(${heroProps.iconImage.imagePath @ context='uri'});">

 

Arun Patidar

AEM LinksLinkedIn

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @Tahera_BegumSh 

Try with below uri context

style="background-image: url(${heroProps.iconImage.imagePath @ context='uri'});">

 

Arun Patidar

AEM LinksLinkedIn

Avatar

Level 4

Hi @Tahera_BegumSh ,

 

Whenever we have to render URL string in HTL, you have to ensure to provide content as uri. This will ensure url string renders properly on generated HTML without any issues.

<div style="background-image: url(${filepath @ context='uri'});">