Img URL in a partial

Hi,

I have the following code within a partial:

<div class="first" style="background-image: url(https://source.unsplash.com/random);background-size: cover;"
></div>

It works with an external img src but I would like to replace the image src by a image defined in the config file, located in theme’s static directory.

[params]
heroimg = "/images/heroimg.jpg" 

I tried the following code unsucessfully:

<div class="first" {{ with .Site.Params.heroimg }}style="background-image: url({{ .Site.Params.heroimg | absURL }});background-size: cover;"{{ end }}>
</div>

Any help to to implement the correct UR or advice for a simpliest way to do it.

Hi,

The “dot” context changes inside a with. Try url({{ . | absURL }}) and you may also need to pipe to safeCSS or one of the other safe* functions.

Thanks for the swift anser.
It works with relURL instead of absURL

<div class="first"{{ with .Site.Params.heroimg }}style="background-image: url({{ . | relURL }});background-size: cover;"{{ end }}
>

I have also to investigate your advice about SafeCSS as I am still a newbie.