Using Default Tokens in Email

Please note:

Unfortunately, using default tokens as described in this help files does not work with Mosaico. It only works with the traditional email method.

Using default tokens in the traditional CiviMail interface

When sending a mass email, you may want to insert a “token” that will be replaced by a value specific to the person receiving the email. For example:

Dear {contact.first_name},

In this example, {contact.first_name} is replaced by the actual person's first name for each email sent.

But what if the record does not have a first name?

In the above example, people without a first name entered would get an email addressed to: “Dear ,”.

That's not right!

To avoid that situation, you can create defaults when adding tokens so that if a value is empty, you can use a default value. For example, suppose you wanted the email to say: “Dear {contact.first_name},” if the contact has a value for first name, but “Dear Friend,” if there is no value.

You can do that with the following code:

{capture assign=first_name}{contact.first_name}{/capture}
Dear {$first_name|default:Friend},

Let's break it down:

For every token that you want to have a default value for, you must first add a capture line:

{capture assign=first_name}{contact.first_name}{/capture}

In this example, contact.first_name is the name of the token. You can get a list of tokens available for your mailing by clicking the Tokens link. The part: assign=first_name creates the variable called first_name – you can use any variable name you want, as long as you reference it in your email with the same spelling and preceded by a dollar sign (e.g. $first_name). You can have as many of these lines as you want – one for each token that you would like to set a default value for.

Last we have:

Dear {$first_name|default:Friend},

Note: you must use the variable you defined with a dollar sign ($first_name), not the name of the token (contact.first_name).

In addition, you may not have any spaces in the default option.

Please note: these instructions only apply to email messages – they do not work for PDF letters or other items that have tokens.

Email and Postal Mailings