Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm trying to create a conditional email template that will show fields based off ticked checkboxes. In the statements, I would like to include a link in standard HTML format Sample Text but the output isnt what I'm looking for.

Here is an example of my code:

<messaging:emailTemplate subject="Quote Request Update" recipientType="User" relatedToType="Account">
<messaging:htmlEmailBody >

Hello {!relatedTo.name},
<br/><br/>
Greeting

<br/><br/>Example {!if(relatedTo.sample__c = true,'<a href="http://www.google.com">Google</a>','Value if False')}

</messaging:htmlEmailBody>
</messaging:emailTemplate>

The output will show the message but will display the "a tag" code instead of displaying the way normal HTML coding would result in. I'm pretty new to VF, trying to hack my way through this. Any help is appreciated.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Visualforce tries really hard to not allow potential security issues. One of the things that is included in this is not allowing HTML to be inserted from merge fields, unless it's part of an <apex:outputPanel escape="false"> element.

Really though a better solution would be to use conditionally rendered elements here. Something like:

Example 
<apex:outputLink rendered="{!relatedTo.sample__c = true}" value="http://www.google.com">Google</apex:outputLink>
<apex:outputText rendered="{!relatedTo.sample__c != true}">Value if False<apex:outputText>

The rendered attribute controls if the element is displayed or not, and since they have mutually exclusive values only one of the two will ever be rendered.

share|improve this answer
    
Works perfect, thanks for your help! –  user7505 Mar 24 at 16:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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