Custom email module does not evaluate IF/ELSE correctly
SOLVE
Hi,
I have a bit of an issue with configuring an email module with an IF/ELSE statement base on a transactional email template.
I know all the custom variables we send are properly added to the email (the debug print works), but whatever I do I cannot use any of them to trigger the IF logic correctly.
Attached is a screenshot of the email I'm getting where you can see that the 'nextCharge' parameter is correctly set as 'true' but the 'nextCharge|bool' is not being processed correctly returning and empty '{}'
I even went as far as creating a macro for that, with no success...
{% if nextCharge|bool == true %} We will attempt to charge your card one more time, the next attempt will be on {{ nextChargeDate }}. {% else %} This was the third and last charge attempt. {% endif %} {% endmacro %}
Yes, you can develop this module in Hubspot. First, you can create the custom card listing using Hubspot looping. https://developers.hubspot.com/docs/cms/building-blocks/modules then add the style using CSS. In the module, you can't able to add the CSS but you can add your custom CSS in the email template header section.
Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
The |bool filter is only needed to check inside an if statement. printing the value won't work. Also it's not possible to |pprint the value from it. If you want to set something, you should use it inside the 'if' statement.
So the best approach will be:
nextCharge|bool: {{ nextCharge|pprint }}
If you want to setup conditional logic this can be done as the bool documentation:
{% if nextCharge|bool == true %}
This is true
{% else %}
This is false
{% endif %}
I checked your sample and I got the 'Else' value for your second property.
My code was like:
<!-- isEnabledForEmailV3Rendering: true -->
{% macro test(nextChargeDate, nextCharge) %}
{% set bool = nextCharge %}
bool : <pre>{{ nextChargebool|pprint }}</pre><br>
nextChargeDate: {{ nextChargeDate|pprint }}<br>
nextCharge: {{ nextCharge|pprint }}<br>
nextCharge|bool: {{ bool|pprint }}<br>
{% if nextCharge|bool == true %}
We will attempt to charge your card one more time, the next attempt will be on {{ nextChargeDate }}.
{% else %}
This was the third and last charge attempt.
{% endif %}
{% endmacro %}
{% set nextChargeDate = '2021-06-16T16:03:59Z' %}
{% set nextCharge = 'true' %}
{{ test(nextChargeDate, nextCharge) }}
<hr>
<pre style="display:block;">
"customProperties": {
"fullName": "John Doe",
"last4": "1234",
"transactionAmount": "100.0$",
"transactionDate": "2021-06-09T16:03:59Z",
"nextChargeDate": "{{ nextChargeDate }}",
"nextCharge": "{{ nextCharge }}"
}
</pre>
{% set nextChargeDate = '' %}
{% set nextCharge = 'false' %}
{{ test(nextChargeDate, nextCharge) }}
<hr>
<pre style="display:block;">
"customProperties": {
"fullName": "John Doe",
"last4": "1234",
"transactionAmount": "100.0$",
"transactionDate": "2021-06-09T16:03:59Z",
"nextChargeDate": "{{ nextChargeDate }}",
"nextCharge": "{{ nextCharge }}"
}
</pre>
Custom email module does not evaluate IF/ELSE correctly
SOLVE
@ArtLinkov Does you 'if statement' work if you change it to:
{% if nextCharge == 'true' %} We will attempt to charge your card one more time, the next attempt will be on {{ nextChargeDate }}. {% else %} This was the third and last charge attempt. {% endif %}
So without the use of the `|bool` filter?
Learn more about HubSpot by following me on LinkedIn or YouTube
✅ Did my answer solve your issue? Help the community by marking it as the solution.