function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mike83mike83 

Dynamic usage of static resources

So I have all these sales people images that they would like to have displayed on the sales page relative to the users alias. So I name all the images  the same as the users alias and load them up in the static resources. I just want to call them.  I am imagingin something liek this but I am not sure how to dynaically populate the name of the resource based on the users alias 

So heres a static example  where "initals" is the users alias name.

 

 <img id="repImage" src="{!$Resource.img_initials}" alt="{!Rep_Page__c.User__r.Name}" />

 

 

What I'd like to do is something like this. 

<img id="repImage" src="{!$Resource.img_{!Rep_Page__c.User__r.Alias}}" alt="{!Rep_Page__c.User__r.Name}" /> 

 

I am open to any other options ... ideas? 

Best Answer chosen by Admin (Salesforce Developers) 
JeremyKraybillJeremyKraybill

I'm fairly sure you can't dynamically parse resource names. However, I can think of a way to nearly achieve your goal:

 

1. create a stylesheet which defines div styles for every image you want to upload, e.g.

 

div.jk { background-image:jk.gif; }

Then put the css, plus the images, into a single .JAR/.ZIP file and upload that as a static resource. Then in your markup you can do something like:

 

 

<div class="{!Rep_Page__c.User__r.Alias}">blah</div>

(Obviously along with a stylesheet and URLFOR) to programmatically grab the right image.

 

HTH

 

Jeremy Kraybill

Austin, TX

 

All Answers

JeremyKraybillJeremyKraybill

I'm fairly sure you can't dynamically parse resource names. However, I can think of a way to nearly achieve your goal:

 

1. create a stylesheet which defines div styles for every image you want to upload, e.g.

 

div.jk { background-image:jk.gif; }

Then put the css, plus the images, into a single .JAR/.ZIP file and upload that as a static resource. Then in your markup you can do something like:

 

 

<div class="{!Rep_Page__c.User__r.Alias}">blah</div>

(Obviously along with a stylesheet and URLFOR) to programmatically grab the right image.

 

HTH

 

Jeremy Kraybill

Austin, TX

 

This was selected as the best answer
mike83mike83
Awesome hack man ...thanks that should work great