5.6 Merge Fields and Conditional Blocks
LISTSERV provides the ability to customize mail messages for each recipient by merging in values uploaded with the recipient data or conditionally including blocks of text based on the preferences indicated in the recipient data. These values are taken from columns that are present in the recipient data.
To merge a field into the message, simply enter the field name (or header name in the case of an uploaded file), used in the recipient definition and precede it with an ampersand ("&") and follow it with a semi-colon (";").If the recipients data is derived from a LISTSERV list, then the only merge substitution fields available are &*TO; for the e-mail address and &*NAME; for the name.For a list of available merge fields, click the link Show Merge Fields and Drop-Ins at the bottom of the text box on the HTML Source or the Alternative Text screen. Copy and paste the name of the merged field into the message to ensure the correct name and formatting. (See Figure 24)
The following example demonstrates how overdue book notices can be customized using specific recipient data in the form of the fields EMAIL, NAME, IDNUM, BRANCH, BOOK1, BOOK2, BOOK3. A text message merging the fields might look like this:
In an HTML message, the HTML source should be altered to include the merge fields, being careful to respect the HTML code.
In an HTML message with alternative text, remember to put the merge fields in both the HTML source and the alternative text.
Conditional blocks are coded by using the ".BB", ".ELSE", and ".EB" directives. These directives must each be on a line by itself. The ".BB" directive begins the conditional block, and "condition" follows ".BB" on the same line. The ".ELSE" directive is optional and starts a text block to be used for the opposite condition as was used for the ".BB". The ".EB" directive ends the conditional block. Fields used in a conditional block should be preceded by the ampersand, but should not be followed by a semicolon. Lines that start with dot asterisk ".*" are used as comments and do not appear in the final message to the recipients.
If conditional blocks are used in an HTML message, first create the basic HTML message, then go into the HTML source code and correctly insert the conditional statements, making sure to maintain proper HTML syntax once the directives are followed. The HTML page will now look incorrect because the directives are interpreted as part of the HTML source. It is important to test all possible conditional values in the testing stage (see Section 7.2), to make sure that the HTML code works correctly in all cases.
Mail-merge substitutions and conditional blocks are explained in more detail in the LISTSERV Developer's Guide.