Apex/Visualforce: multiline IF statement in HTML

  • Can I write a multiline if statement in Apex/Visualforce HTML?

    Something like (definitely pseudocode):

    <apex if (condition)>
      <strong>This HTML.</strong>
    <apex else>
      <strong>This is the false HTML.</strong>
    <apex end>


    It seems like the answers here don't work, i.e. neither this:

    <apex:outputPanel rendered="{!IF(Lead.Credit__c > 0)}">

    Nor this work:

    <apex:variable var="v" value="1" rendered="{!IF(Lead.Credit__c > 0)}">

    Does it have to be a boolean value?

  • Ratan Paul

    Ratan Paul Correct answer

    6 years ago

    Use like below

    <apex:outputtext value="!IF(ISNULL(Eslot.sEvent), 'Free', IF(Eslot.sEvent.Appointment_Type__c == 'Personal', 'Pers', 'Fill'))}"/>


    <apex:outputPanel rendered = "{! If(m.Name=='sai' ,true,false) }">
    <apex:outputPanel rendered = "{! If(m.Name=='sam' ,true,false) }">
    <apex:outputPanel rendered = "{! If(m.Name=='test1' ,true,false) }">

    Addition to above

    If you are using html elements and want to hide based on conditions

    <div style= "display: {!If(m.Name=='sai' ,'none','') }">
    <div  style= "display: {! If(m.Name=='sam' ,'none','') }">
    </div >
    <div  rendered = "display:{! If(m.Name=='test1' ,'none','') }">
    </div >

    That's a single line. I need to fit in multiple lines of HTML.

    `!IF(ISNULL(Eslot.sEvent), 'Free', IF(Eslot.sEvent.Appointment_Type__c == 'Personal', 'Pers', 'Fill'))}` this is multiple conditions

    Use rendered tag as I have outlined

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM