首页 > 解决方案 > 无法在 Mailjet 模板“For”循环中使用逻辑

问题描述

我想它曾经让我,不知道发生了什么变化?我无法在 Mailjet 模板“For”循环中使用逻辑。它不喜欢我的FormatNumberif

我的变量:

  "Variables": {
    "CurrentYear": "",
    "OutstandingInvoices": [{"InvoiceNum": "100", "Total": 100.00, "DaysPastDue": "5", "InvoiceMonth": "May", "InvoiceYear": "2021"}],
    "CustomerID": "",
    "CustomerName": "",
    "InvoiceYear": "",
    "InvoiceMonth": ""
  }
}

我的模板代码:

{% for invoice in var:OutstandingInvoices %}
{{invoice.InvoiceMonth}} {{invoice.InvoiceYear}} for {{FormatNumber("$#,###.00", invoice.Total)}} {% if invoice.DaysPastDue > 0 %} : {{invoice.DaysPastDue}} days late {% endif %}
{% endfor %}

给我以下错误:

(1) ERender Error: Expression Parsing Error: Unknown identifier invoice.Total near FormatNumber("$#,###.00", invoice.Total)

(2) ERender Error: Expression Parsing Error: Unknown identifier invoice.DaysPastDue near invoice.DaysPastDue > 0

杂项

我想知道这是否与不能在 for 循环中使用默认值有关(根据我的另一个问题:Mailjet Non-Nested Loop Failing

那么 for 循环中不允许任何类型的逻辑吗?

标签: mailjet

解决方案


经过数小时的搜索,我找到了适合我的解决方案:您需要使用标签包装 for 循环。<mj-raw>

这应该适合你:

<mj-raw>{% for invoice in var:OutstandingInvoices %}</mj-raw>
    ...
<mj-raw>{% endfor %}</mj-raw>

推荐阅读