Sightly template question | Community
Skip to main content
Apr 22, 2019 9:16 PM UTC
Solved

Sightly template question

I am trying to call a template with multiple values (as shown below)

<template data-sly-template.hero="${ @ container,bgImage,props }">

     <div class="${container}" style="background-image: url('${bgImage}');">

          <text>props.title</text>

     </div>

</template>

<sly data-sly-call="${hero @ container='web-container',

                                                       bgImage=properties.bannerImage,

                                                       props=properties}" />

The 'container' and 'props' paraemeters are rendering correctly; however bgImage is not rendering at all.

Example of Output:

<div class="web-container" sytle="background: url('');">

     <text>My Title</text>

</div>

When I try to print ${properties.bannerImage} I am able to render it "/some/path/to/file.jpeg"

Is this a bug or am I doing something wrong?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Prince_Shivhare
Prince_ShivhareAccepted solution
New Participant
Apr 23, 2019 4:58 AM UTC

Hi Daniel,

I tested the article Creating an Experience Manager Responsive Banner Component  again. and I am able to set the background image.

could you please check the syntax again?

<div class="jumbotron" style="background-image:url('${banner.backimage @ context='styleString'}');">

~ Prince

15 replies

eric_vangeem
Level 2
Apr 23, 2019 1:31 PM UTC

I would expect 'styleToken' or 'styleString' to work here (I always get these two mixed up), but if they are both not working then you should be fine to use 'unsafe' as long as you are sure this is not user-inputted data from end-users. From your example it looks like this may be authored, so you should be safe.

Translate
Apr 23, 2019 1:21 PM UTC

Thank you all for your help.

The issue was the sightly preventing xss attacks

Doing as Price said is the optimal answer.

Translate
smacdonald2008
Level 10
Apr 23, 2019 8:00 AM UTC

Thxs Prince for confirming Article workss

Translate
Prince_Shivhare
Prince_ShivhareAccepted solution
New Participant
Apr 23, 2019 4:58 AM UTC

Hi Daniel,

I tested the article Creating an Experience Manager Responsive Banner Component  again. and I am able to set the background image.

could you please check the syntax again?

<div class="jumbotron" style="background-image:url('${banner.backimage @ context='styleString'}');">

~ Prince

Translate
Apr 23, 2019 3:19 AM UTC

Hi Eric,

unsafe does work!! 

I can finally render the background images.

Is this the best solution or is there a way to render the background image while having xss protection?

Translate
eric_vangeem
Level 2
Apr 23, 2019 3:14 AM UTC

Can you try with ${bgImage @ context='unsafe'} ? This should hopefully rule out any issues with accessing that property.

Translate
Apr 23, 2019 3:09 AM UTC

Hi Eric

I did as you recommended.  It does not work

Translate
eric_vangeem
Level 2
Apr 23, 2019 3:06 AM UTC

There is a syntax error with your expression:

url('${bgImage @ context='styleToken'}');

Remove the outer single quotes. It should look like this:

url(${bgImage @ context='styleToken'});

Translate
Apr 23, 2019 3:05 AM UTC

I can render the uri outside the template

${properties.mobileImage}

${properties.bannerImage}

I can output both of these uri

Also, when I do the following they also render with the background image

<!-- The div disappears when on larger screens -->

<div class="component-mobile-container" style="background-image: url('${properties.mobileImage}');">

      <text>props.title</text>

     ...

</div>

<!-- The div disappears when on smaller screens -->

<div class="component-container" style="background-image: url('${properties.bannerImage}');">

      <text>props.title</text>

     ...

</div>

It is only when I try to use a template it fails

Translate
smacdonald2008
Level 10
Apr 23, 2019 2:58 AM UTC

Look at our example that does work. you still must be missing something. Are you sure the dialog nodes match you names in the HTL code?

Translate