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
UmapenUmapen 

Changing the Static Resource(image) name dynamically -

I have a sites pages that has the following line of code that have image.

 

 

<apex:page showHeader="false">
<apex:image id="Holidays" value="{!$Resource.default1}" width="220" height="55" />

 

I want to change the images based on the field value in the ojbect.

My custom object name  holidays__c. Custom page  titled  holidayspecialpage.

with custom field season__c. I have a custom controller and page works fine on sites page.

 

I want to change the image in my apex page based on the value of season__c

 if(season__c = summer) static resouce summer image.

How can I acheive this?

Best Answer chosen by Admin (Salesforce Developers) 
RyanGuestRyanGuest

How dynamic are the static resources that you want to use?

 

 

A quick hack I could think of is to include all the resources on your page, but use the rendered attribute on the apex:image tag to determine whether or not the image should be shown.

All Answers

RyanGuestRyanGuest

How dynamic are the static resources that you want to use?

 

 

A quick hack I could think of is to include all the resources on your page, but use the rendered attribute on the apex:image tag to determine whether or not the image should be shown.

This was selected as the best answer
UmapenUmapen
Currently we are limiting 6 images. The static Resource name remains same. When we have to change we will load the image again with same name. no more then 6 iamges
pierpipierpi
Hey Umapen,
If I am not too late and most importantly if I understood what you want to do, you can have VF dynamically select the image to load using the <apex:image url="{!URLFOR($Resource.ImagesZip, ctrl.imageByFieldValue)}" />.  You need to package all your images in a zip file and delegate the ctrl to determine the exact file to load using the relative path.  This way the VF does not need to know what are the images associated with what field value(s).
 
I hope I was clear enough.
 
Cheers
Pierpaolo