Why is boolean assignment not working in my liquid email template?

I’m writing a custom email template, such that given the types of product in the order, different text blocks are added. I have two types:

  • products with ‘voucher’ tag
  • products that have ‘evento’ in the title

So, I wrote a search logic to count and save to variables how many products of each kind there are in the order and, given the count, display additional text.

The issue is with the title conditional: if I check using a direct boolean, it works, but assigning to a variable does not work, as shown in a test email below.

This is the snippet that checks each product type. If the conditional work as intended, both approaches should output false or true, and this is where the issue manifests: in one approach its true, in another false

The line should assign a boolean value, indicating if we have ‘evento’ in the title.

{% assign title_contains_evento = downcased_title contains 'evento' %}

Thus, both approaches should output the same boolean value, but they do not

{% assign title_contains_evento = downcased_title contains 'evento' %}

{% if title_contains_evento %}
...
{% if downcased_title contains 'evento' %}

Here there is the full order counting script

{% assign event_count = 0 %}
{% assign voucher_count = 0 %}

{% for item in subtotal_line_items %}
    {% for tag in item.product.tags %}
        {% if tag == 'voucher' %}
        <br>tem um voucher por tag no carrinho..<br>
            {% assign voucher_count = voucher_count | plus: 1 %}
        {% endif %}
        {% break %}
    {% endfor %}
  
    {% assign downcased_title = item.product.title | downcase %}
   
    <br>Lowercased title: {{ downcased_title }}<br>
    <br>Does the title contain 'evento'? Both ways should output the same<br>

    {% assign title_contains_evento = downcased_title contains 'evento' %}

    {% if title_contains_evento %}
    <br>true1<br>
    {% else %}
    <br>false1<br>
    {% endif %}

    {% if downcased_title contains 'evento' %}
    <br>true2<br>
    {% else %}
    <br>false2<br>
    {% endif %}

        {% if downcased_title contains "evento" %}
            <br>There is a event in cart.. {{downcased_title}}<br>
            {% assign event_count = event_count | plus: 1 %}
        {% endif %}
{% endfor %}

Here is a sample from the rendered email, which has true1 and false2, indicating that the two approaches are not equal. Here I bought two different voucher types and expected to have two groups of outputs, each group equal.

Tem um voucher por tag no carrinho..> > Lowercased title: voucher teste rodizio> > Does the title contain ‘evento’? Both ways should yield the same> > true1> > false2> > tem um voucher por tag no carrinho..> > Lowercased title: voucher teste rodizio alternativo> > Does the title contain ‘evento’? Both ways should yield the same> > true1> > false2> > Voucher text..> > Total de eventos no carrinho:> > 0> Total de vouchers no carrinho:> > 2> > [> {> “id”:12281895256203,> “title”:“Voucher teste rodizio - Voucher Completo”,> “price”:“0.00”,> “line_price”:“0.00”,> “quantity”:2,> “product”:{> “id”:7139863888011,> “title”:“Voucher teste rodizio”,> “body_html”:“\u003cp\u003eashashsaas asdasdsadasdasdas\u003c/p\u003e”,> “vendor”:“Ambiente de Teste”,> “product_type”:“”,> “created_at”:“2023-05-25T17:01:09-03:00”,> “handle”:“rodizio-completo”,> “tags”:“voucher”,> “variants”:[> {> “id”:41451243274379,> “product_id”:7139863888011,> “title”:“Voucher Completo”,> “price”:“0.00”,> “sku”:“”,> “position”:1,> “inventory_policy”:“continue”,> “compare_at_price”:“”,> “fulfillment_service”:“manual”,> “inventory_management”:null,> “option1”:“Voucher Completo”,> }> ],> },> “fulfillment”:null> },> {> “id”:12281895288971,> “title”:“Voucher teste rodizio alternativo - Voucher Completo”,> “price”:“0.00”,> “line_price”:“0.00”,> “quantity”:1,> > “variant_id”:41511937540235,> > “product”:{> “id”:7160284348555,> “title”:“Voucher teste rodizio alternativo”,> “body_html”:“\u003cp\u003eashashsaas asdasdsadasdasdas\u003c/p\u003e”,> “vendor”:“Ambiente de Teste”,> “product_type”:“”,> “template_suffix”:null,> “published_scope”:“web”,> “tags”:“voucher”,> },> “fulfillment”:null> }> ]

I’ve uploaded the full liquid code for the email template here https://pastebin.com/wBf7LREL