问题
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
回答1:
I have found the answer here: http://help.mandrill.com/entries/28427818-Can-I-use-dynamic-or-conditional-merge-tags-
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|*
回答2:
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|*
来源:https://stackoverflow.com/questions/25088996/conditional-content-in-mandrill-template