Conditional logic through HTML code

Hi everyone, I have a question related to a HubSpot custom quote template.

Is it possible to create a type of conditional logic via Hub HTML? More specifically, I wanted to create a table that can only appear if a specific line item type is selected.

I tried to create something using:

“{% set itens_horas = [] %}
{% for item in line_items %}
{% set nome_normalizado = item.name|upper|trim %}
{% if “HORA” in nome_normalizado %}
{% set itens_horas = itens_horas + [item] %}
{% endif %}
{% endfor %}
{% if itens_horas|length > 0 %}”

but despite that, it ended up not working. Is there a specific way?

The primary issue you have is that you cannot SET variables in a FOR loop that was created outside it’s block. This is why it’s not working.

You can cheat it, however, by doing using the DO command to update an array or object:

So where you have the line:

{% set itens_horas = itens_horas + [item] %}

You can use APPEND to push the name of the item into the array.

{% do itens_horas.append(nome_normalizado) %}

What’s pushed into the array doesn’t seem to matter (eg, you can simply push in true if you wanted) as you look to be just checking the array length later.