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

conditional colour display in visual force page.

we have a VF page with 14 boolean flags that are rendered as either true or false. 


In the current page I am having <apex:outputfields> tags in <apex:pageblocksectionitem> which are displayed as true/false without color.


Now I am required to display them based on color. My approach now is having two outputfiled  tags for each boolean flag and render them on the visualforce page with h1 and h2 tags having different colors styles for both of them.


Is there any way the visualfore page detects true or false values and render them with red color when it is false and green color when it is true.In this way I can just have only <apex:outputfiled> tag for each boolean flag.


I think you should be able to do this via styling.  Something like:


<apex:outputField style="color: {!IF(val==false,'red','green')}" value="{!val}" />


 (Edited to replace ternary operator with IF function which actually works!)