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
danielfnzdanielfnz 

Get Static Resource Dynamically

Hi,

I am trying to determine if it is possible to determine the static resource dynamically.

So e.g. I have 2 users who have alias of User1 and User2. I have 2 images User1.jpg and User2.jpg and they should see their corresponding image when they view the visualforce page.

I want to do something like
$Resource.($User.Alias).jpg

But I can't get the syntax right if it is at all possible.

Any advice appreciated. Thanks


Message Edited by danielfnz on 09-01-2008 03:18 AM
danielfnzdanielfnz
My solution to this problem is to name the static resources as a concatenation of first name and last name. Once uploaded I get the url of the resource and add it to the controller code.

The controller uses UserInfo.getFirstName() and UserInfo.getLastName() to determine which URL to return to the visualforce page.

Not ideal as the controller code needs to be updated everytime a static resource is changed or a new one uploaded, so I'm still interested in a smarter solution if someone can see one.

Thanks
Mark YoungMark Young
Take a look at the URLFOR function.  This allows you to upload a single zip as a static resource with all of the images inside.
 
Eg:
Code:
<img src="{!URLFOR($Resource.TestZip,$User.FirstName & '_' & $User.LastName & '.jpg')}" />