Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Im trying to assign a variable that has been converted from a string but the result variable stays as a string
{% assign multi_qty = multi_qty_str | to_i %}
{% if multi_qty > 0 %}{% endif %}
The above throws an error "Liquid error: comparison of String with 0 failed"
The below works but is it possible to avoid type casting each time
{% assign multi_qty = multi_qty_str | to_i %}
{% if multi_qty | to_i > 0 %}{% endif %}
I've tried:
{% assign multi_qty = (multi_qty_str | to_i) %}
And:
{% assign multi_qty = multi_qty_str | to_i + 0%}
but still show the same error
Problem solved:
{% assign multi_qty = multi_qty_str | to_i | abs %}
works
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024