I'm facing a weird challenge where I need to include a static resource image inside an aura:iteration loop.
The challenge here is this:
<img src="{!$Resource.testbox}"/>
This will display the image in the lightning component fine.
But if you want different images to be displayed based on a List you're running through aura:iteration the challenge begins. How do I structure the src to use the variable to set the static resource name? (the dt.img variable contains 'testbox', I have triple checked)
<aura:iteration items="{!v.extraDecoderTypes}" var="dt" indexVar="idx">
<img src="{!$Resource + dt.img}"/>
</aura:iteration>
In my head this should work fine, but it does not. So I guess the problem is that $Resource should be $Resource. (with "."). But if I do that in the code, I will get this error:
expecting an identifier, found '+' at column 12 of expression: $Resource. + dt.img
Trying without the "." will get uploaded to org, but the image will not display.
https://developer.salesforce.com/docs/atlas.en-us.234.0.lightning.meta/lightning/expr_resource_value_provider.htm does not mention this exact case, but more how to get resource that are below one level in the directory structure.
Any tips would be greatly appreciated!
$Resource.namedoes not work that way since the path varies with upload timestamps for different static resources. You need the specific full references or you need to put all your static resources into a ZIP static resource. See the documentation.