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
p_harroldp_harrold 

Email Template Line Break within a conditional IF statement

Within an if statement I want to print a line break to the screen. However, there seems to be no easy way to do this in any forums thus far. I found a few answers, but none of them seem to work within the TRUE argument in my IF conditional statement. Here is a snippet of my code:
{! IF (relatedTo.Budget_In_Stream_Video__c != null, "In-Stream Video", null)}
{! IF (relatedTo.Budget_Interactive_InStream_Video__c != null, "Interactive In-Stream Video", null)}

Outputs

I have tried \n, <br/>, and many others with little or no success. BR() only gives this output:
In-Stream Video_BR_ENCODED_Interactive In-Stream Video

 

Someone please tell me I'm crazy and this isn't that hard and doesn't require some crazy hack...

Chris ZhuangChris Zhuang

Do you just use the if statement in your Email Template?

What type of the email template do you create?

Have you try CHAR(10)?

 

kriskkrisk
Chris ZhuangChris Zhuang

I don't think any VF tags will work in the Email Template...

p_harroldp_harrold

@Chris

I don't only use the if statement in my email template. I am currently using HTML format, not plain text, because I only want a line feed when the if statement is true. Here is the whole section of the template with the if statements: 

Ad Units:
{! IF (relatedTo.Budget_In_Stream_Video__c != null, "In-Stream Video" , null)}
{! IF (relatedTo.Budget_Interactive_InStream_Video__c != null, "Interactive In-Stream Video
", null)}
{! IF (relatedTo.Budget_In_Stream_Video_Blend__c != null, "In-Stream Video (Blend)", null)}
{! IF (relatedTo.Budget_FPA__c != null, "Smartphone Full Page", null)}
{! IF (relatedTo.Budget_App_Banner__c != null, " Smartphone Banner", null)}
{! IF (relatedTo.Budget_In_Banner_Video__c != null, "Smartphone In-Banner Video", null)}
{! IF (relatedTo.Budget_Tablet_Full_Page__c != null, "Tablet Full Page", null)}
{! IF (relatedTo.Budget_Tablet_Leaderboard__c != null, "Tablet Banner", null)}
{! IF (relatedTo.Budget_Tablet_In_Banner_Video__c != null, "Tablet In-Banner Video", null)}
{! IF (relatedTo.Budget_Video_Blend__c != null, "Video (Blend)", null)}
{! IF (relatedTo.Budget_Display_Blend__c != null, "Display (Blend)", null)}
{! IF (relatedTo.Budget_Sponsorship__c != null, "Sponsorship", null)}

 

Basically, what I want to do is create a list of these items, but not have them spaced out in a weird way. I want a line feed after each if statement, but only if it turns out to be true.

 

I don't know about CHAR(10) or how you would format that. I've tried this: 

{! IF (relatedTo.Budget_In_Stream_Video__c != null, "In-Stream Video"+'CHAR(10)' , null)}

But no luck.

p_harroldp_harrold

@krisk

I tried <apex:outputPanel>, but got nothing. What do you use for the line feed? I tried \n, <br/> and &BR() with no luck. Also, the rendered attribute defaults to true for outputpanel so no need to specify it even though I did...

p_harroldp_harrold

I guess there really isn't a possible solution to this...

Cloud ShareCloud Share
For anyone coming to this page for displaying conditional linebreaks in email template:

<apex:outputText rendered="{! IF (relatedTo.Budget_In_Stream_Video__c != null)}">In-Stream Video<br/></apex:outputText>

The  outputtext along with the linebreak will be rendered  only when the Budget_In_Stream_Video__c !=null. Otherwise, the text and the linebreak are both not displayed.

 
Bob DeRosierBob DeRosier
I tried  "<apex:outputText..."  in an email template and it only echoed the "<apex:outputText  after calculating what was inside the {}. I don't think that works with email templates.
Muhammad.BilalMuhammad.Bilal
I tried all the above solutions but nothing worked and I found this solution on some other website. IF condition can simply go into an output panel where "Rendered" condition true or false will determine the visibility of the panel. In my case, if the string in the field contains "TRU;" the panel will show. 

<apex:outputPanel rendered="{!IF(contains(relatedTo.mySalesforceField__c,'TRU;'), true, false)}">
        This line will show when the value in the mySalesforceField contains TRU;
</apex:outputPanel>