Search code examples
templatingmailjet

Mailjet templating - conditional decision when a variable is N/A


I am making a footer component with an image in Mailjet and want there to be two options for the image.

  1. The image is defined though the variable sender_image
  2. The variable sender_image is not defined and a fallback image is used
<table align="center" width="100%">
  <tr>
    <th>
      <div style="margin: 16px auto; text-align: center;">
        {% set image = var:sender_image:"N/A" %}
        {% if image != "N/A" %}
            <img src="{{image}}" style="max-width:120px;margin:0 auto;">
        {% else %}
            <img src="https://link_to_the_image.de/image.png" style="max-width:120px;margin:0 auto;">
        {% endif %}
      </div>
    </th>
  </tr>
</table>

In the Mailjet preview this works well (for both conditions), but when I send the email out I get the following error:

A template language occurred when sending a message using Template 4935390: unknown node ## near ## voir

SET IMAGE ##

I've incorporated code from this stackoverflow answer and tried to refactor several times - so far to no avail.

Does anyone know what I'm doing wrong?
Thank you! :)


Solution

  • This was able to be solved using the following code:

    <table align="center" width="100%">
      <tr>
        <th>
          <div style="margin: 16px auto; text-align: center;">
            <img src= {{var:image:"https://link_to_the_image.de/image.png"}} style="max-width: 120px; margin: 0 auto;">
          </div>
        </th>
      </tr>
    </table>
    

    Not having a "set" method and instead using the standard Mailjet convention of providing a default value for a variable var:var_name:"var_default_value".