I am creating a confirmation email to be sent when a new Orders__c is created via an external form. These are not related objects so an <apex:repeat> solution is not viable. There are 50+ fields that may be shown and I would like to avoid having a bunch of blank rows.

My ideal solution would be the equivalent of adding rendered="{!IF(relatedTo.Item1__c == null, false, true)}" to the <tr> tag, but I don't reckon that's an option in static HTML.

    <messaging:emailTemplate relatedToType="Orders__c" subject="Order Received: {!relatedTo.Name}" replyTo="[email protected]">

        <messaging:htmlEmailBody >

                <p>Thank you for submitting your order. It has been received and will be processed shortly. You will receive notification when the order has shipped.</p>
                    <p>Order Summary</p>
                <p>Order:               {!relatedTo.Name}</p>
                <p>Order Received:      {!relatedTo.Submitted__c}</p>
                <p>Date Needed By:      {!relatedTo.Date_Needed_By__c}</p>
                <p>Site Code:           {!relatedTo.Site_Code__c}</p>
                <p>TCA Name:            {!relatedTo.TCA_Name__c}</p>
                <p>TCA Email:           {!relatedTo.TCA_Email__c}</p>
                <p>TCA Phone:           {!relatedTo.TCA_Phone__c}</p>

                <p>Total Items Ordered: <apex:outputField value="{!relatedTo.Total_Items_Ordered__c}" /></p>
                <p>Notes: <apex:outputField value="{!relatedTo.Notes__c}" /></p>

                    <table border="1">                      

                        <tr> //HIDE THIS IF Item1__c == 0
                            <td>Item1: </td> //HIDE THIS IF Item1__c == 0
                            <td colspan="2"> <apex:outputField value="{!relatedTo.Item1__c}" /> </td> //HIDE THIS IF Item1__c == 0
                        </tr> //HIDE THIS IF Item1__c == 0
                        <tr> //HIDE THIS IF Item2__c == 0
                            <td>Item2: </td> //HIDE THIS IF Item2__c == 0 
                            <td colspan="2"> <apex:outputField value="{!relatedTo.Item2__c}" /> </td> //HIDE THIS IF Item2__c == 0
                        </tr> //HIDE THIS IF Item2__c == 0

                        /* long list of items*/


  • why not wrap the <tr> with apex:outputPanel and use rendered= there?
    – cropredy
    Commented May 16, 2016 at 18:25

1 Answer 1


You can use display:none; in a style attribute to hide elements.

<table style="{!IF(relatedTo.Item1__c == null, 'display: none;', '')}">

Don't forget, if you want to also check for 0 values, you need your criterion to be:

OR(ISBLANK(relatedTo.Item1__c), relatedTo.Item1__c == 0)
  • Thanks Adrian. Can I tack style="{!IF...}" to the <tr> tag? It looks like this method would result in a disjointed table for each individual line item.
    – JaredT
    Commented May 16, 2016 at 17:53
  • @jatuttle0 Yes, you can implement it on any given element.
    – Adrian Larson
    Commented May 16, 2016 at 17:54
  • <tr style="{!IF(!relatedTo.Item1__c == null || relatedTo.Item1__c == 0, 'display: none;', '')}"> is coming back with Error: Incorrect parameter type for function 'not()'. Expected Boolean, received Number
    – JaredT
    Commented May 16, 2016 at 18:29
  • @jatuttle0 Please edit your question with what you tried and your error text at the bottom. Why did you negate your null check?
    – Adrian Larson
    Commented May 16, 2016 at 18:30
  • Turns out I made a whoopsie and had {!IF(!relatedTo...)}. Works now that I took out the extra !
    – JaredT
    Commented May 16, 2016 at 18:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .