无法在 Mailjet 模板“For”循环中使用逻辑

Swe*_*ato 2 mailjet

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

我的变量:

  "Variables": {
    "CurrentYear": "",
    "OutstandingInvoices": [{"InvoiceNum": "100", "Total": 100.00, "DaysPastDue": "5", "InvoiceMonth": "May", "InvoiceYear": "2021"}],
    "CustomerID": "",
    "CustomerName": "",
    "InvoiceYear": "",
    "InvoiceMonth": ""
  }
}
Run Code Online (Sandbox Code Playgroud)

我的模板代码:

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

给我以下错误:

(1)ERender错误:表达式解析错误:未知标识符invoice.Total接近FormatNumber(“$#,###.00”,invoice.Total)

(2) ERender错误:表达式解析错误:未知标识符invoice.DaysPastDue接近invoice.DaysPastDue > 0

杂项

我想知道这是否与无法在 for 循环中使用默认值有关(根据我的其他问题:Mailjet Non-Nested Loop Failing

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

小智 7

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

这应该适合你:

<mj-raw>{% for invoice in var:OutstandingInvoices %}</mj-raw>
    ...
<mj-raw>{% endfor %}</mj-raw>
Run Code Online (Sandbox Code Playgroud)