Comparison operators in custom Quote template not working

I’m customing the Modern Quote template to display the available quantity of the product, but we want to only show if that number is postive. So I wrote

{% if unit.available_qty %}Avail. Qty: {{ unit.available_qty }}{% endif %}

Which correctly displays the number. then I wrote

{% if unit.available_qty > 0 %}Avail. Qty: {{ unit.available_qty }}{% endif %}

to only show if the number is greater than zero. This doesn’t display anything though, regardless of what the number is.

Is there any reason a comparison wouldn’t work in Templates, or is there another sort of syntax I should be using?

@JDavis48

It might be worth checking to see if the value is returing as an number use the type function detailed here

If it isn’t, you can convert it to an integer

That worked, thank you so much! The full line is now:

{% if unit.available_qty|int > 0 %}Avail. Qty: {{ unit.available_qty|format_currency(“en-GB”, “GBP”, false)|replace(‘£’, ‘’)|replace(‘.00’, ‘’) }}{% endif %}

So it checks if the available quantity (converted to an integer) is greater than zero, and if so it prints the available quantity (converted to currency with the label and decimal places hidden, which was the most direct way to have commas display).