[SalesForce] == condition is not working in rendered attribute of

VF CODE SNIPPET

<apex:pageBlockSection id="abcd" title="Closed Lost Information" rendered="{!(Opportunity.StageName=='Closed Lost')}">
        <apex:inputField label="Opportunity Name" value="{!Opportunity.Reason_Lost__c}"/><p/>
  </apex:pageBlockSection>

I am new to salesforce and I am having below question. As shown in above snippet, I need to render the "apex:pageBlockSection" if StageName value is equal to 'Closed Lost'. (StageName is a picklist of standard object opportunity)

Here the condition is not returning proper true or false value to render or hide the "apex:pageBlockSection" .

Can anybody please help me to figure out what is wrong with my approach ?

Thanks in advance 🙂

Best Answer

Normally, you'd use a boolean variable, but you can also use an If statement to achieve the same results. Try the following for the rendered expression:

rendered="{!If(Opportunity.StageName='Closed Lost',true,false)}