Your software
My Mautic version is: 5.1.1 / GrapeJS
My PHP version is: 8.2
My Database type and version is: latest MySQL
Your problem
I cannot figure out how to use if/else conditionals.
Is there no support in Mautic for if/else conditionals?
I am sending some transactional emails from API, which pass some tokens. I’ve been able to display the token values from API with {name}, {username}, {siteUrl}, etc.
But I’ve tried various combinations of {% if value == 1 %}
{% else %}
using <mj-raw>
, without <mj-raw>
.
I also tried {% TWIG-BLOCKS %} plugin but that just blew up my Mautic server and I had to reinstall everything.
Some example code I tried:
<mj-text font-size="36px" align="center">
{% TWIG_BLOCK %}
{% if is_gift == 1 %}
<p>You received a gift!</p>
{% elseif is_gift == 0 and conversationCount == 1 %}
<p>New message from {user_1_displayName}</p>
{% else %}
<p>You have {messageCount} new messages</p>
{% endif %}
{% END_TWIG_BLOCK %}
</mj-text>
<mj-text font-size="36px" align="center">
{% TWIG_BLOCK %}
{% if is_gift %}
<p>You received a gift!</p>
{% elseif not is_gift and conversationCount %}
<p>New message from {user_1_displayName}</p>
{% else %}
<p>You have {messageCount} new messages</p>
{% endif %}
{% END_TWIG_BLOCK %}
</mj-text>
<mj-text font-size="36px" align="center">
<mj-raw>
<!--
{% TWIG_BLOCK %}
{% if is_gift %}
<p>You received a gift!</p>
{% elseif not is_gift and conversationCount %}
<p>New message from {user_1_displayName}</p>
{% else %}
<p>You have {messageCount} new messages</p>
{% endif %}
{% END_TWIG_BLOCK %}
-->
</mj-raw>
</mj-text>
So while I still had the MauticAdvancedTemplateBundle installed, this ALWAYS resulted in the ELSE condition.
Regardless of my API token value {is_gift}
being 1, 0, “1”, “0” and the same for {conversationCount}
of 1, 2, “1”, “2”.
Is there any way to get this working?
Do I need to be wrapping bits in <mj-raw>
(and if so, which bits)?
I also tried {% set label = "This is a label" %}
and couldn’t get that to display, it would always output the literal {label} instead of the value.
Any suggestions on how to get this basic code working?
Spent the last 8 hours on this and the documentation is non-existent on how to do this properly.