【问题标题】:Conditional content in Mandrill templateMandrill 模板中的条件内容
【发布时间】:2014-09-25 04:11:27
【问题描述】:

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

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

更改订阅偏好

我怎样才能写出类似的东西,甚至这可能吗?

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

【问题讨论】:

    标签: templates if-statement conditional-statements mandrill


    【解决方案1】:

    我在这里找到了答案: 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 的值,则条件将评估为 false。

    使用 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|*
    

    【讨论】:

    • 我认为这与只提供一个可能有一天会失效的链接而不提供任何有用信息有关。例如,如果您添加了像 Hemerson Varela 对您的链接所做的信息,那会很好。或者至少解决您的问题
    【解决方案2】:

    Mandrill 支持条件标签

    基本 IF 条件

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

    基本 IF-ELSE 条件

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

    ELSEIF 条件

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

    否定条件

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

    【讨论】:

      猜你喜欢
      • 2016-05-19
      • 1970-01-01
      • 2013-02-12
      • 2014-07-07
      • 2014-11-03
      • 2021-10-05
      • 2013-10-26
      • 2014-10-20
      • 2017-01-26
      相关资源
      最近更新 更多