5

I am handing over dictionary keys (key value pair) to a service which in turn utilizes the api to send the email via Mandrill.

Now, if my key is blank then i dont want it to be included in the email. Like in the following scenario, i only want the link text to display if my key has some value.

<a href="|UPDATE_PROFILE|" target="_blank" >change subscription preferences</a>

How can i write it some thing like or even is this possible?

if *|UPDATE_PROFILE|* IS NOT EMPTY
BEGIN
<a href="*|UPDATE_PROFILE|*" target="_blank">change subscription preferences</a> 
END
Nakilon
  • 34,866
  • 14
  • 107
  • 142
learning...
  • 3,104
  • 10
  • 58
  • 96

2 Answers2

12

I have found the answer here: https://mailchimp.com/developer/transactional/docs/templates-dynamic-content/

Here is the info from the page:

Conditional merge tags support traditional IF, ELSE, and ELSEIF logic as well as IFNOT negative 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|*

Use in mycase

*|IF:UPDATE_PROFILE|*
                    <p>IMPORTANT NOTE: *|LAYOUTYEAR|*  
                        available for review at: http://www.somesite.org/SomePage.</p>
                *|ELSE:|*
                    <p>
                        <a href="http://www.somesite.org/SomePage" target="_blank">Click here</a>
                        to view the detailed specs.
                    </p>
                *|END:IF|*
Breith
  • 2,160
  • 1
  • 23
  • 32
learning...
  • 3,104
  • 10
  • 58
  • 96
  • 1
    I think it has to do with only giving a link that could one day be dead and not putting any useful information. For example if you had added infos like Hemerson Varela did with your link that would have been fine. Or at least the solution to your issue – eXa Nov 02 '15 at 07:00
3

Mandrill supports conditional tags

Basic IF condition

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

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

Basic IF-ELSE condition

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

ELSEIF condition

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

Negative conditions

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

*|IFNOT:UPDATE_PROFILE|*
    content to display if UPDATE_PROFILE is not provided
*|ELSE:|*
    content to display if UPDATE_PROFILE is provided
*|END:IF|*
Hemerson Varela
  • 24,034
  • 16
  • 68
  • 69