CMS Development

JDavis48
Participant | Platinum Partner
Participant | Platinum Partner

Comparison operators in custom Quote template not working

SOLVE

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?

0 Upvotes
2 Accepted solutions
dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

Comparison operators in custom Quote template not working

SOLVE

@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

View solution in original post

0 Upvotes
JDavis48
Solution
Participant | Platinum Partner
Participant | Platinum Partner

Comparison operators in custom Quote template not working

SOLVE

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).

View solution in original post

0 Upvotes
2 Replies 2
JDavis48
Solution
Participant | Platinum Partner
Participant | Platinum Partner

Comparison operators in custom Quote template not working

SOLVE

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).

0 Upvotes
dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

Comparison operators in custom Quote template not working

SOLVE

@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

0 Upvotes