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
Lori StippLori Stipp 

Embed line break in apex:outputtext in Visualforce HTML email template

I have looked and looked and can't find an answer to this problem. Any ideas?

I have a Visualforce HTML email template that uses apex:outputtext to render a number of fields conditionally, like this:

<apex:outputText value="Survey Name: {!relatedTo.Survey__r.Name}"
                  rendered="{!IF(relatedTo.Survey__r.Yes_or_No__c ='Yes', TRUE,FALSE)}"/><br/>

I have many such apex:outputtext statements in a row. Ideally, I'd like the <br/> behavior to be embedded inside the value string, so it is also rendered conditionally. Otherwise, if many of my fields are not displayed because of the value of their rendered attribute, I get a lot of extranous blank space in my generated email.

I would like to be able to do something like:

<apex:outputText value="Survey Name: {!relatedTo.Survey__r.Name}\n\r"
                  rendered="{!IF(relatedTo.Survey__r.Yes_or_No__c ='Yes', TRUE,FALSE)}"/><br/>

Can anyone help?
Thanks in advance!!!
 
Best Answer chosen by Lori Stipp
cmoylecmoyle
Also, if you just need a line break after each of your statements, you can do away with the <br/> entirely by setting the display to block on the style for that tag.
<apex:outputText value="Survey Name: {!relatedTo.Survey__r.Name}"
                  rendered="{!IF(relatedTo.Survey__r.Yes_or_No__c ='Yes', TRUE,FALSE)}" style="display:block;"/>

 

All Answers

cmoylecmoyle
You could try these:
<apex:outputPanel layout="inline" rendered="{!IF(relatedTo.Survey__r.Yes_or_No__c ='Yes', TRUE,FALSE)}">
	<apex:outputText value="Survey Name: {!relatedTo.Survey__r.Name}"/>
	<br/>
</apex:outputPanel>

This might work also:
<apex:outputText value="Survey Name: {!relatedTo.Survey__r.Name}"
                  rendered="{!IF(relatedTo.Survey__r.Yes_or_No__c ='Yes', TRUE,FALSE)}">
<br/>
</apex:outputText>

 
cmoylecmoyle
Also, if you just need a line break after each of your statements, you can do away with the <br/> entirely by setting the display to block on the style for that tag.
<apex:outputText value="Survey Name: {!relatedTo.Survey__r.Name}"
                  rendered="{!IF(relatedTo.Survey__r.Yes_or_No__c ='Yes', TRUE,FALSE)}" style="display:block;"/>

 
This was selected as the best answer
Lori StippLori Stipp
Thanks so much! I think all of these solutions would work, but I went with the display:blockk solution. Thank you, thank you!