+ Start a Discussion
JimPDXJimPDX 

Static Resource, Dynamic file?

Sorry for what might be a stupid question here. I would like the file reference within my URLFOR($Resource) to be dynamic - either a variable set in my controller or in the VF page itself. Can this be done? I am trying to show dynamic images within a page based on which page you are on. Thx.

 

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber

Not a stupid question a common ask. You have to specify the resource explicitly using $Resource.resourcename but if it's an image you want to reference dynamically you can bundle the images into a zip, upload the zip as a static resource and then specify which element within the zip you want to show dynamically.

 

Check out the introduction to Visualforce article and scroll down close to the bottom to the Miscellanea section for the brief description to Static Resources and later the sample custom component where this is demonstrated.

All Answers

mtbclimbermtbclimber

Not a stupid question a common ask. You have to specify the resource explicitly using $Resource.resourcename but if it's an image you want to reference dynamically you can bundle the images into a zip, upload the zip as a static resource and then specify which element within the zip you want to show dynamically.

 

Check out the introduction to Visualforce article and scroll down close to the bottom to the Miscellanea section for the brief description to Static Resources and later the sample custom component where this is demonstrated.

This was selected as the best answer
JimPDXJimPDX
I have been bundling all my images (TONS of images) into ZIP files and referencing them by name 'path/image.jpg' - now I see in the intro doc where I can insert the name dynamically. Thanks Andrew!
VisualForceVisualForce

Hi..

       I have to display all zipped files in a Picklist.. That is if I zip 3 files a.gif,b.gif,c.gif into one file and upload into static resource. In my VF page I have to display this 3 names in a picklist. I have to store the selected picklist value, based on the picklist selection I have to change the logo in my PDF generation.

        From Zip file we can fetch the appropriate file. But how to display the zipped files names in Picklist..?

Is it possible..?