Search code examples
templatesif-statementconditional-statementsmandrill

Conditional content in Mandrill template


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

Solution

  • 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|*