+ Start a Discussion
BaguiarBaguiar 

Display a HTML based on an IF statement in VF

I've searched a bit and found some posts about using the IF statement within a VF page, but wasn;t clear about the possibility of using it for a simple display of a html page.

 

The controller is the standard ACCOUNT object.

All I need is something like this:

 

<apex:page standardController="account">
{!IF(isnull(account.JOB__c),"No Job","

<html>

some HTML coding here....

</html>"
)
}
</apex:page>

 The syntax is probably wrong, but I was wondering if this is possible.

 

Thanks in advance!

B

Best Answer chosen by Admin (Salesforce Developers) 
TheSwamiTheSwami

That use case is probably not the best for an "IF" - This is way to do what you are describing:

 

<apex:page standardController="account">
    <apex:outputPanel rendered="{!isblank(account.JOB__c)}">
        No Job
    </apex:outputPanel>
    
    <apex:outputPanel rendered="{!Not(isblank(account.JOB__c))}">
        Has Job
    </apex:outputPanel>
</apex:page>

 

All Answers

TheSwamiTheSwami

That use case is probably not the best for an "IF" - This is way to do what you are describing:

 

<apex:page standardController="account">
    <apex:outputPanel rendered="{!isblank(account.JOB__c)}">
        No Job
    </apex:outputPanel>
    
    <apex:outputPanel rendered="{!Not(isblank(account.JOB__c))}">
        Has Job
    </apex:outputPanel>
</apex:page>

 

This was selected as the best answer
BaguiarBaguiar

Thanks!

It works pretty much but with one detail:

 

I have a html code for a twitter page exactly where you have the "Has job" sentence. like this:

 

<apex:page standardController="account"> 

<apex:outputPanel rendered="{!isblank(account.Twitter_Page_id__c)}"> No Twitter </apex:outputPanel>

<apex:outputPanel rendered="{!Not(isblank(account.Twitter_Page_id__c))}"> 
 
<html>

<body>
<div id="Twitter feeds"></div>
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 10,
  interval: 30000,
  width: 470,
  height: 475,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#E0FFFF',
      color: '#00008b',
      links: '#142433'
    }
  },
  features: {
    scrollbar: true,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('{!account.Twitter_Page_id__c}').start();
</script>
</body>

</html>

</apex:outputPanel> 

</apex:page>

</apex:outputPanel> 

</apex:page>

 All the HTML works fine, but it does not render the Twitter_page_id__C with the line:

}).render().setUser('{!account.Twitter_Page_id__c}').start();

 the page shows up, backgrouond, twiter logo, but not the feeds, because it can't read the twitter id from the line above. Might be syntax again ?

 

Thanks  in advance!

B

BaguiarBaguiar

BTW,

 

If I use only the HTML, without the <apex:outputpnael> , it works just fine with {!account.Twitter_page_id__C}

 

B

BaguiarBaguiar

never mind.. it is working now. with the same code. Might have pasted the field without the ". But thanks!