Sightly template question | Community
Skip to main content
April 22, 2019
Solved

Sightly template question

  • April 22, 2019
  • 15 replies
  • 10513 views

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.
Best answer by Prince_Shivhare

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
New Participant
April 23, 2019

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.

April 23, 2019

Thank you all for your help.

The issue was the sightly preventing xss attacks

Doing as Price said is the optimal answer.

smacdonald2008
New Participant
April 23, 2019

Thxs Prince for confirming Article workss

Prince_Shivhare
Prince_ShivhareAccepted solution
New Participant
April 23, 2019

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

April 23, 2019

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?

eric_vangeem
New Participant
April 23, 2019

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

April 23, 2019

Hi Eric

I did as you recommended.  It does not work

eric_vangeem
New Participant
April 23, 2019

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'});

April 23, 2019

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

smacdonald2008
New Participant
April 23, 2019

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?