About Dynamic and Conditional Merge Tags

Mandrill supports conditional merge tags. Because Mandrill doesn't store list data, all merge tag values need to be provided in the API call or SMTP headers, and the conditions would be checking against those values.

Conditional merge tags support traditional IF, ELSE, and ELSEIF logic as well as IFNOT negative conditions.

Examples

Basic IF and ELSE conditions

Use IF conditions to display content only when the condition evaluates as true.

*|IF:MERGE|*
content to display if a value for MERGE is provided
*|END:IF|*


*|IF:MERGE=x|*
    content to display if the value for MERGE is x
*|END:IF|*

When using a condition like *|IF:MERGE=x|*, and no value for MERGE is provided, the condition will evaluate as false.

Use IF and ELSE conditions to display content when a condition is true, but alternate content when the condition evaluates as false.

*|IF:MERGE|*
    content to display
*|ELSE:|*
    alternative content
*|END:IF|*

The ELSEIF condition

Use ELSEIF to display one of several possible options. Only the content following the first condition evaluated as true will be displayed—other conditions will be skipped.

*|IF:MERGE=x|*
    <p>content to display if the value for MERGE is x</p>
*|ELSEIF:MERGE=y|*
    <p>content to display if the value for MERGE is not x, but is y</p>
*|ELSEIF:MERGE=z|*
    <p>content to display if the value for MERGE is not x or y, but is z</p>
*|ELSE:|*
    <p>alternate content to display if the value for MERGE is not x, y, or z</p>
*|END:IF|*

Nested conditions

*|IF:MERGE1=x|*
    *|IF:MERGE2=y|*
          <div mc:edit="main"> 
                <p>content to display if both conditions are true</p>
           </div>
    *|END:IF|*
*|END:IF|*

Negative conditions

*|IF:MERGE!=x|*
    content to display if the value for MERGE is not x
*|ELSE:|*
    content to display if the value for MERGE is x
*|END:IF|*


*|IFNOT:MERGE|*
    content to display if MERGE is not provided
*|ELSE:|*
    content to display if MERGE is provided
*|END:IF|*