Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mailjet templating - conditional decision when a value in var is (not) null

Tags:

mailjet

Is it possible to conditionally check and decide if var:<my_var> is null | not null?

I am might be missing something obvious, but so far did not find how to do it in https://dev.mailjet.com/email/template-language/.

Hacky approach which works:

{% set my_var = var:my_var:"N/A" %}
{% if my_var != "N/A" %}
  {{my_var}}
{% endif %}
like image 276
NenadP Avatar asked Oct 19 '25 03:10

NenadP


1 Answers

This is what we are using too, but I would recommend adding a check for an empty string too.

Mailjet API sometimes doesn't like to accept null properties.

<mj-raw>
{% set my_var = var:my_var:"N/A" %}
{% if my_var != "N/A" and my_var != "" %}
</mj-raw>
... some html ...

<mj-raw>
{% endif %}
</mj-raw>
like image 72
peter Avatar answered Oct 22 '25 03:10

peter