5

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.

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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