+ Start a Discussion
Ashish Agrawal 4Ashish Agrawal 4 

Need to display a images(logo) based on if condition[Conditional images].

Hello Developers,

Developement about display conditional images on apex:image(display only one images if condition are true).

i have tried using apex:image components and error comes:

Error: using value attribute in apex: image both condition(true or false) broken images(no  images) are display.

And, using rendered attribute in apex: image no images are display.

so how to overcome this. need to display a images(logo) based on if condition.

<apex:page standardController="Account" >
<apex:form >
<apex:pageBlock title="Conditional image page">
<apex:pageBlockSection title="Image Section">
<apex:image value="{if(account.Rating =='Hot',$Resource.image1,'')}" width="100" height="100"/>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

Thanks& Regards
Ashish Agrawal
Best Answer chosen by Ashish Agrawal 4
Anoop yadavAnoop yadav
Hi Ashish,

You can Try like this.

<apex:outputPanel rendered = "{!account.Rating =='Hot'}" >
   <apex:image value="{!$Resource.image1}" width="100" height="100"/>
</apex:outputPanel>

<apex:outputPanel rendered = "{!account.Rating =='Warm'}" >
   <apex:image value="{!$Resource.image2}" width="100" height="100"/>
</apex:outputPanel>

All Answers

Anoop yadavAnoop yadav
Hi Ashish,

You can Try like this.

<apex:outputPanel rendered = "{!account.Rating =='Hot'}" >
   <apex:image value="{!$Resource.image1}" width="100" height="100"/>
</apex:outputPanel>

<apex:outputPanel rendered = "{!account.Rating =='Warm'}" >
   <apex:image value="{!$Resource.image2}" width="100" height="100"/>
</apex:outputPanel>

This was selected as the best answer
RishavRishav
Hii Ashish
                   Try this code 
<apex:page standardController="Account" >
<apex:form >
<apex:pageBlock title="Conditional image page">
<apex:pageBlockSection title="Image Section">
<apex:image value="{!(if(account.Rating =='Hot',$Resource.image1,''))}" width="100" height="100"/>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

Ashish Agrawal 4Ashish Agrawal 4
Hi Rishav! Thanks for u r valuable feedback but i already tried this code.
Ashish Agrawal 4Ashish Agrawal 4
Hello developers
How to reduce the gap between two images
how to reduced the size between two images.