function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nicholas MilevskyNicholas Milevsky 

Rendering output text in visualforce email template with multiple conditions

Hi,

I'm a beginner with Visualforce, so please excuse my stupidity.

I'm pulling my hair out trying to get output text to render when there is more than one condition.  If it's just one, there's no problem.  However, the second I want to use OR or AND (and I've tried it 50 different ways), it will not work for me.  I'm just trying to render something in the email if the opportunity stage is either "Verbal" or "Closed Won".  I'm not using any custom controller as it didn't seem necessary.  This is what the code currently looks like:

<apex:outputPanel rendered="{!(relatedTo.StageName =='Verbal' || relatedTo.StageName =='Closed Won')}">
Block of verbage.
</ apex:outputPanel>

I have tried it with OR() as well.  I've tried having the "!" on both relatedTo segments, and many others.  I've looked all over for the answer, and none of the fixes seem to work for me.

Thank you!
Best Answer chosen by Nicholas Milevsky
Rishab TyagiRishab Tyagi
Hello Nicholas,

This simple code works for me in a Visualforce template.
<messaging:htmlEmailBody >
    <apex:outputPanel rendered="{!OR(relatedTo.StageName =='Verbal', relatedTo.StageName =='Closed Won')}">
        Block of verbage.
    </apex:outputPanel>
</messaging:htmlEmailBody>
Please, do verify that you don't have any spaces in the tag names as it was giving me an error with the </ apex:outputPanel> tag due to space after /. Once the template is saved try doing the send test and verify merge fields.
 

All Answers

Rishab TyagiRishab Tyagi
Hello Nicholas,

This simple code works for me in a Visualforce template.
<messaging:htmlEmailBody >
    <apex:outputPanel rendered="{!OR(relatedTo.StageName =='Verbal', relatedTo.StageName =='Closed Won')}">
        Block of verbage.
    </apex:outputPanel>
</messaging:htmlEmailBody>
Please, do verify that you don't have any spaces in the tag names as it was giving me an error with the </ apex:outputPanel> tag due to space after /. Once the template is saved try doing the send test and verify merge fields.
 
This was selected as the best answer
Nicholas MilevskyNicholas Milevsky
Thanks Rishab.  I swear I tried this before, but it definitely worked this time.  I may have jumped to conclusions when looking at the preview before and thought it didn't work.  This definitely resolved it!

Oh and the space was only a mistake I typed in here and was not in my code.  Again thanks!