The variable is resolved just fine. The reason your url()
value is empty is because you're not using the right Display Context. Also, the value, you're passing there, the string "my Title"
, is not a valid URL (what you need to print) or a valid style token (what usually gets rendered in a style
attribute)
You'll notice that each of the following expressions renders an empty url()
value:
<div style="background: url(${'cookies'});"></div>
<div style="background: url(${'cookies with chocolate chips'});"></div>
<!--/* both print background: url();*/-->
If we force the display context to allow any string, the value will be printed
<div style="background: url(${'cookies' @ context='unsafe'});">
</div>
<!--/* prints background: url(cookies);*/-->
In script
and style
contexts, HTL requires the display context to be stated explicitly. If it's not, the output is not rendered.
What you want to output to show a background image is the URL of an image. Let's try making this explicit:
<div style="background: url('${'/etc/designs/myapp/img/someimage.png' @ context='uri'}');">
</div>
<!--/* prints background: url('/etc/designs/myapp/img/someimage.png');*/-->
There, that does the trick!
Now, as a word of advice, try to avoid inline styling. You'll save yourself similar problems with display contexts and your CSS will be easier to maintain if it's part of a client library.