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


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.

1 Answer 1


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:


<apex:outputLink rendered="{!relatedTo.sample__c = true}" value="http://www.google.com">
<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.


You must log in to answer this question.

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