Just-in-time content suppression with a Comment Token
You're minutes away from sending an email when you realize: Oops, some leads shouldn't see that paragraph!
What do you do when it's too late to segment and replace a section with a snippet?
- You could clone the email and mess with your carefully-tuned Smart Lists and Campaigns.
- You could delete the part you forgot to segment, but the boss wouldn't like that.
- You could become an instant whiz at Velocity like me ☺ and extract all the HTML into a script token (but let's assume you're not there yet).
- You could create a tiny script token to dynamically comment out an HTML section for some leads!
Here's an example of such a token, in full:
#set( $badStates = ['RI','DE','NJ'] )
#if( $badStates.contains($lead.State) )
#if( !$inBadState )
#set( $inBadState = true )
<!--
#else
#set( $inBadState = false )
-->
#end
#end
Notice a couple of elegant things happening here.
One, I'm creating a Velocity/Java ArrayList so I can check for multiple matches at once. I'm going to be looking for leads either in RI, DE, or NJ, so the ArrayList::contains
method is a lot easier to read than a ton of OR conditions.
Two, I'm resetting a variable ($inBadState
) every other time the script runs and finds a match. Since every HTML comment requires an opening <!--
and a closing -->
, this allows me to reuse the same script token over and over in my email body. The first time, it outputs the opening tag. The second time, it outputs the closing tag. The third time, it outputs another opening tag. And so on.
To use it in the email body, just wrap your hideable blocks like so:
{{my.allowedStatesOnly}}
<div>
Here's your special offer, pardner!
</div>
{{my.allowedStatesOnly}}
<div>
some other general stuff...
</div>
<div>
still other stuff for general audiences...
</div>
{{my.allowedStatesOnly}}
<div>
And don't forget that special offer we told you about above!
</div>
{{my.allowedStatesOnly}}
Depending on the lead's State, blocks will be either hidden:
<!--
<div>
Here's your special offer, pardner!
</div>
-->
or left visible:
<div>
Here's your special offer, pardner!
</div>
Caveats
This script will only work in the HTML version of an email, as <!-- -->
has no meaning in the text version.
And only use this technique to hide information that would not cause a total catastrophe if the recipient deliberately looked in their HTML source. You're not deleting anything from the body of the email; you're showing good faith that you didn't mean to show discounts to the wrong subgroup, etc. (You could even add some text in the comment like **This section is not valid for the current recipient** so if they do peek at the text or HTML source they know it isn't for them.)
So, not a long-term approach to dynamic content, but a useful tool when time is tight.