note: You didn't supply the CSS for your .row, .column, .left, and .right classes so I had to guess what it looked like, as the background images won't show without the related div elements having a height value.
1. The main issue with your 1st example is that you are trying to reference the $imageName story variable directly within the String value being assigned to style attribute, and you can't do that without using Attribute Directive markup. The following is a modified version of your example.
/* Some test data. */
<<set $objects to {
"banana": {
name: "Banana",
description: "A Banana",
hasItem: true
},
"apple": {
name: "Apple",
description: "An Apple",
hasItem: true
}
}>>
/* Show the inventory. */
<<set _inventory to Object.keys($objects)>>\
<<for _i to 0; _i< _inventory.length; _i++>>
\<<set _obj to $objects[_inventory[_i]]>>
\<<set _style to "background-image: var(--image" + (_i + 1) + ");">>
\<<if _obj.hasItem>>
\<div class="row">
\<div class="column left" @style="_style"></div>
\<div class="column right">
\<b><i>_obj.name</i></b>
\<br>_obj.description
\</div>
\</div>
\<</if>>
\<</for>>
2. Your solution is also using some advanced CSS functionality like the :root pseudo-class and the CSS variables var() function, and neither of these features are available within all the commonly used web-browsers (as you can see in the Browser compatibility section of the MDN pages I linked to).
The following example uses your suggestion of changing the items with the $object variable to include an imageurl property.
/* Some test data. */
<<set $objects to {
"banana": {
name: "Banana",
description: "A Banana",
imageUrl: "https://vignette.wikia.nocookie.net/fallout/images/0/0a/Scrap_metal.png/revision/latest?cb=20140406155837",
hasItem: true
},
"apple": {
name: "Apple",
description: "An Apple",
imageUrl: "https://image.freepik.com/free-icon/bandage-cross_318-61786.jpg",
hasItem: true
}
}>>
/* Show the inventory. */
<<set _inventory to Object.keys($objects)>>\
<<for _i to 0; _i< _inventory.length; _i++>>
\<<set _obj to $objects[_inventory[_i]]>>
\<<set _style to "background-image: url('" + _obj.imageUrl + "');">>
\<<if _obj.hasItem>>
\<div class="row">
\<div class="column left" @style="_style"></div>
\<div class="column right">
\<b><i>_obj.name</i></b>
\<br>_obj.description
\</div>
\</div>
\<</if>>
\<</for>>