2
$array = [
  "low_price_low_stock_goods" => []
]

In my mailjet template

   {% for item in var:low_price_low_stock_goods %}
       <tr>
           <td>{{ item.good_name }}</td>
           <td>{{ item.value }}</td>
           <td>{{ item.count }}</td>
       </tr>
   {% endfor %}

error is now No value for "var:low_price_low_stock_goods"

Ricky ponting
  • 4,537
  • 4
  • 13
  • 26
  • `"low_price_low_stock_goods" => []` it means your `"low_price_low_stock_goods"` index have empty array.since it's an empty array so how can you get any value from it? – Alive to die - Anant May 16 '17 at 08:56
  • @AlivetoDie So my for loop should not execute or i want to check if array is not empty then only run for loop. – Ricky ponting May 16 '17 at 09:02
  • `check if array is not empty then only run for loop`->this is what you have to do – Alive to die - Anant May 16 '17 at 09:05
  • @AlivetoDie but how I do check array is not empty in mailjet template? – Ricky ponting May 16 '17 at 09:11
  • @aridjar Have you any idea in that? – Ricky ponting May 16 '17 at 09:29
  • Hi from Mailjet. When you are trying to loop on array, which is empty, it is not skipped, but an error is thrown instead - it's the current behavior. We are aware of the troubles it causes and will work on fixing it in future. At the moment, there is no really useful workaround. – Zhivko May 16 '17 at 11:30
  • @Zhivko ok fine what i am doing i am passing then yes, no from my php in mjml. So can you give me code if condition yes then only for loop run. if my if condition false and for loop inside loop still i got error. – Ricky ponting May 16 '17 at 11:38

1 Answers1

1

As I answered you on Github Ricky: it's a known issue on Mailjet's templating language side, sorry for that. To avoid it, just pass a valid object in the API call for the low_price_low_stock_goods value. This will work:

{
  item.good_name: "",
  item.value: "",
  item.count: ""
}
Nicolas Garnier
  • 370
  • 1
  • 10