lea*_*... 3 templates if-statement conditional-statements mandrill
我将字典键(键值对)移交给服务,该服务又利用api通过Mandrill发送电子邮件.
现在,如果我的密钥是空白,那么我不希望它被包含在电子邮件中.就像在下面的场景中一样,我只希望显示链接文本,如果我的键有一些值.
<a href=" |UPDATE_PROFILE|"target="_blank">更改订阅偏好</a>
我怎么能写出一些类似的东西,甚至可能呢?
if *|UPDATE_PROFILE|* IS NOT EMPTY
BEGIN
<a href="*|UPDATE_PROFILE|*" target="_blank">change subscription preferences</a>
END
Run Code Online (Sandbox Code Playgroud)
我在这里找到了答案:http: //help.mandrill.com/entries/28427818-Can-I-use-dynamic-or-conditional-merge-tags-
以下是该页面的信息:
条件合并标签支持传统的IF,ELSE和ELSEIF逻辑以及IFNOT负面条件.
仅当条件评估为true时,才使用IF条件显示内容.
*|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|*
Run Code Online (Sandbox Code Playgroud)
使用像| IF:MERGE = x |这样的条件时 ,并且没有提供MERGE的值,条件将评估为false.
使用IF和ELSE条件在条件为真时显示内容,但在条件评估为false时显示备用内容.
*|IF:MERGE|*
content to display
*|ELSE:|*
alternative content
*|END:IF|*
Run Code Online (Sandbox Code Playgroud)
ELSEIF条件
使用ELSEIF显示几个可能的选项之一.仅显示评估为真的第一个条件之后的内容 - 将跳过其他条件.
*|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|*
Run Code Online (Sandbox Code Playgroud)
嵌套条件
*|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|*
Run Code Online (Sandbox Code Playgroud)
负面条件
*|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|*
Run Code Online (Sandbox Code Playgroud)
在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|*
Run Code Online (Sandbox Code Playgroud)