Custom email module does not evaluate IF/ELSE correctly

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…

Code I’m using in the module:

<!-- isEnabledForEmailV3Rendering: true -->

{% macro test(nextChargeDate, nextCharge) %}
nextChargeDate: {{ nextChargeDate|pprint }}<br>
nextCharge: {{ nextCharge|pprint }}<br>
nextCharge|bool: {{ nextCharge|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 %}

{{ test(custom.nextChargeDate, custom.nextCharge) }}

-------------------------------------

Here are the custom properties I’m using for testing:

nextCharge = true

“customProperties”: {

“fullName”: “John Doe”,

“last4”: “1234”,

“transactionAmount”: “100.0$”,

“transactionDate”: “2021-06-09T16:03:59Z”,

“nextChargeDate”: “2021-06-16T16:03:59Z”,

“nextCharge”: “true”

}

nextCharge = false

“customProperties”: {

“fullName”: “John Doe”,

“last4”: “1234”,

“transactionAmount”: “100.0$”,

“transactionDate”: “2021-06-09T16:03:59Z”,

“nextChargeDate”: “”,

“nextCharge”: “false”

}

-------------------------------------

If anyone encountered this issue before, I would really appreciate an advice.

Thanks,

Art

Hi @ArtLinkov , I had a similar issue when trying to use if / else statements. All I needed to do to fix my issue was adding the following beta: Create programmable emails
I see you’ve added the right template tag in your code, but is the beta active in the portal that you are using?

@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?

Thanks @Teun that did the trick!

Hi @ArtLinkov,

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>

Thanks @Indra it did help me with debugging another issue I had!

Hi @ArtLinkov ,

Yes, you can develop this module in Hubspot. First, you can create the custom card listing using Hubspot looping. Modules Overview - HubSpot docs
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.
Thanks and Regards.