Q: How can I send an email with LISTSERV Maestro, where different recipients see different images?
By Johannes Hubert Senior Applications Programmer, L-Soft
Images in HTML emails have become ubiquitous and are useful in many situations. In some cases, you may even want to show different images to different recipients based on some predefined criteria, similar to mail-merge but with images instead of text. This tech tip shows how you can accomplish this in LISTSERV Maestro.
For illustration, we'll use the example of a customer newsletter. The newsletter is for a subscription-based service that has different subscription tiers – bronze, silver and gold. The newsletter is supposed to include a short "subscription status" section that informs individual recipient about their subscription tier and expiration date. This information is available for each recipient in two merge fields: &TIER; and &EXPIRATION;. You can create this status section using standard mail-merging:
Now you want to spice up this status message with a small image that additionally illustrates the subscription tier with a matching image of a bronze, silver or gold badge, for example like this:
To achieve this, first edit your message to include all three badge images:
At first glance, it may look strange to have all images visible at once, but don't worry, we'll make sure that each recipient only sees the correct image.
As the next step, we switch into code mode, where our subscription status section currently looks like this:
As you can see, there is one <img> tag for each of the three possible badge images. But of course we only want one of these images to be visible for each recipient. To achieve this, we simply use HTML comments to comment out all but one of the images. For example, to show only the gold badge, we would use HTML comments like this:
Of course, using hard-coded HTML comments like above would not have the desired effect. It would simply mean that the bronze and silver images are always commented out, and the gold badge is visible for all recipients. So to make this react differently for each recipient, we need a bit of logic that conditionally inserts the comments in the correct way.
For this type of condition, we use the {{*Calc}} system drop-in, with the "If" formula function. The syntax of this function is as follows:
If(condition, value1, value2), and the function evaluates the condition and returns either "value1" (if the condition is "true") or "value2" (if the condition is "false").
This means, that such an If-function can be used to define the final replacement value for the {{*Calc}} system drop-in, which is most useful if the condition uses a merge field so that the result is different for individual recipients. For example, consider this system drop-in:
{{*Calc If(&FIELD;="abc", "yes", "no")}}
The condition is true, if the &FIELD; has the value "abc". In this case the function returns the value "yes", so the {{*Calc}} drop-in is replaced with the text "yes". If the &FIELD; has a different value, the function, and thus the system drop-in, results in the value "no" instead.
We can use a similar condition to replace the {{*Calc}} drop-in with an empty text (in other words, the {{*Calc}} drop-in is simply removed without any replacement) or with a text that contains an opening HTML comment tag. For example:
This replaces the {{*Calc}} drop-in with an empty text if the &TIER; is bronze, or with an opening HTML comment tag otherwise. And, of course, we can do a similar condition for the closing comment tag. We then wrap the two conditions around our bronze image like this:
As a result, the two {{*Calc}} drop-ins will simply be removed if the &TIER; is bronze, or they will be replaced with opening and closing HTML comment tags otherwise, effectively "hiding" the bronze image inside of a HTML comment:
If &TIER; is bronze, the result of the above is:
In all other cases, this is the result instead:
Armed with these conditional {{*Calc}} drop-ins, we can now surround our three badge images with conditional HTML comments so that each image is visible only if the &TIER; field has the matching value, and the other images are commented out:
As a result, depending on the value of the &TIER; field, each recipient now sees only the matching badge image:
Next Steps
|