2

I think it used to let me, not sure what changed? I cannot use logic inside of a Mailjet Template "For" loop. it does not like my FormatNumber or if

My Vars:

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

My Template Code:

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

Gives me the following errors:

(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

Misc

I wonder if it is related to not being able to use default values in for loops as well (as per my other question: Mailjet Non-Nested Loop Failing)

So logic of any kind is not allowed in a for loop?

SweetTomato
  • 509
  • 1
  • 6
  • 16

1 Answers1

6

after hours of searches, I've found the solution for me : You need to wrap for loops using <mj-raw> tag.

This should works for you:

<mj-raw>{% for invoice in var:OutstandingInvoices %}</mj-raw>
    ...
<mj-raw>{% endfor %}</mj-raw>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Vincent Vaur
  • 61
  • 1
  • 2
  • It's provide in the documentation, but there's no really clear example. https://dev.mailjet.com/email/template-language/mjml/ – cisco_bro Aug 06 '21 at 13:20