templates - Mandrill 模板中的条件内容

标签 templates if-statement conditional-statements mandrill

我正在将字典键(键值对)移交给一个服务,该服务又利用 api 通过 Mandrill 发送电子邮件。

现在,如果我的 key 是空白的,那么我不希望它包含在电子邮件中。就像在以下场景中一样,如果我的 key 具有某些值,我只希望显示链接文本。

更改订阅偏好

我怎么能写一些类似的东西,甚至这可能吗?

if *|UPDATE_PROFILE|* IS NOT EMPTY
BEGIN
<a href="*|UPDATE_PROFILE|*" target="_blank">change subscription preferences</a> 
END

最佳答案

我在这里找到了答案:
https://mailchimp.com/developer/transactional/docs/templates-dynamic-content/
这是页面上的信息:
条件合并标签支持传统的 IF、ELSE 和 ELSEIF 逻辑以及 IFNOT 否定条件。
仅当条件评估为真时才使用 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|*
当使用类似 |IF:MERGE=x| 的条件并且没有为 MERGE 提供值时,条件将评估为假。
使用 IF 和 ELSE 条件在条件为真时显示内容,但在条件评估为假时使用替代内容。
*|IF:MERGE|*
    content to display
*|ELSE:|*
    alternative content
*|END:IF|*
ELSEIF 条件
使用 ELSEIF 显示几个可能的选项之一。只会显示第一个评估为 true 的条件之后的内容 - 其他条件将被跳过。
*|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|*
嵌套条件
*|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|*
负面条件
*|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|*
在我的情况下使用
*|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|*

关于templates - Mandrill 模板中的条件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25088996/

相关文章:

javascript - 为什么在 jQuery 中同时调用 if 和 else 条件?

python - 如何根据两个条件过滤 csv 文件中的特定行? (使用 Pandas )

Python - 根据其他数据帧列中满足的条件填充 PANDAS 数据帧列

c++ - 拆分参数包

Python 3 'else' 在这个循环中如何工作

python - 具有不同条件语句的函数返回

c# - 有什么方法可以阻止光线转换穿过物体吗?

c++ - 存储和重新使用 decltype 值?

parsing - GAE Go template.Execute,传递带有向量的结构

c++ - 使用带有 void 函数的模板