0

I have a custom object that I am trying to display using visualforce. Some of the fields in the custom object may not have data. I want to check this and only if the data exists, then print the html to display the field. How can I do that?

Below is the code that I am trying to write, which is giving me syntax error.

<apex:repeat var="v" value="{! results }">
    <div class="typeHeader">
         {! v.Name}
    </div>
    <h3>My Field</h3>
    <div class="mystyle">
         {! v.myfield }
    </div>
    {! IF (({! v.URL__c == null}), true, <h3>URL</h3><div class="mystyle">{! v.URL__c }</div>) }
</apex:repeat>

As you can see I am trying to display some HTML only if URL__c field has some data in it. Could you please help me with this?

Thanks!

1

You can use apex:outputtext, or apex:outputpanel to render data conditionally with rendered attribute.

example apex:outputText :

<apex:outputText rendered="{! v.URL__c != null}" >
<!-- your code -->
</apex:outputText>

example apex:outputpanel :

<apex:outputpanel rendered="{! v.URL__c != null}" >
<!-- your code -->
</apex:outputPanel>

if you want just plaintext the you can even use if formula as follows

{!if(v.URL__c == null, 'Its Null', 'IT has value')}

Reference for apex:Outputtext

Reference for apex:OutputPanel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.