kentico macro not resolving in-line style

Nathan Brunetti asked on October 15, 2019 22:02

I'm trying to set a background-image in the before field of a webpart using the image that was uploaded on the Form tab of the page.

This is what I have so far but the inline style for background-image is not loading: <div id="HeroDiv_BG" class="HeroDiv_BG" style="background: url('/getattachment/{% CurrentDocument.GetValue("MenuItemTeaserImage") @%}/attachment.aspx');">

But if I use the same macro in an img tag it does work: <img src="/getattachment/{% CurrentDocument.GetValue("MenuItemTeaserImage") @%}/attachment.aspx');" />

Recent Answers


Peter Mogilnitski answered on October 16, 2019 16:25

you have syntax error extra single quote and bracket and semicolon you ca do this:

<img src='/getattachment/{% CurrentDocument.GetValue("MenuItemTeaserImage") @%}/attachment.aspx' />

0 votesVote for this answer Mark as a Correct answer

Nathan Brunetti answered on October 16, 2019 17:01

Peter thanks for noting the syntax error in the img tag but I was only using that as an example of what worked. I need to get the background-image macro to work, which is the first example. Can you assist with that?

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 16, 2019 17:38

remove single quotes and use absolute url:

<div id="HeroDiv_BG" class="HeroDiv_BG" style="background-image: url( http://www.mydomain.com/getattachment/{% CurrentDocument.GetValue("MenuItemTeaserImage") @%}/attachment.aspx)">

the format is:

<div style="background-image: url(http://url.jpg)"></div>

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on October 16, 2019 20:56 (last edited on December 10, 2019 02:31)

Hi Nathan,

Try this

<div style='background-image: url({% ResolveUrl("~/getattachment/" + CurrentDocument.GetValue("MenuItemTeaserImage") + "/image") |(identity)GlobalAdministrator%});'>
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.