mailjet - 无法在 Mailjet 模板“For”循环中使用逻辑
问题描述
我想它曾经让我,不知道发生了什么变化?我无法在 Mailjet 模板“For”循环中使用逻辑。它不喜欢我的FormatNumber
或if
我的变量:
"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 循环中不允许任何类型的逻辑吗?
解决方案
经过数小时的搜索,我找到了适合我的解决方案:您需要使用标签包装 for 循环。<mj-raw>
这应该适合你:
<mj-raw>{% for invoice in var:OutstandingInvoices %}</mj-raw>
...
<mj-raw>{% endfor %}</mj-raw>
推荐阅读
- heroku - /tmp 大小在 Heroku 上波动
- python - 是否可以在 Windows 中使用 pyAutoGui 和调暗屏幕
- python - 计算连贯性分数时出错 – AttributeError: 'dict' object has no attribute 'id2token'
- mysql - mysql 5.7 使用时的过程语法错误不存在
- javascript - 在 React 中的函数内更新类的状态
- python - 一个热编码/虚拟日期
- c - 如何为 ARM-Linux (IMX6UL) 编译 BlueZ 应用程序?
- html - 如何限制div内的文本
- angular - Angular 8 HTTP INTERCEPTOR 中断订阅
- python - 使用 GPU PyOpenCL 优化 python 代码的不同方法:内核 GPU/PyOpenCL 中的外部函数