I am trying to do some basic arithmetic in Jekyll's liquid templating engine. I have assigned one variable numColumns and I am trying to use it in a conditional statement.
{% assign numColumns = 3 %}
Note I omitted the outer for loop in the below expression where loopindex comes from. Regardless, this works with the - operator and correctly evaluates to 2.
{% if loopindex == 3 - 1 %}
However, these alternatives I tried do not work:
{% if loopindex == numColumns - 1 %}
{% if loopindex == numColumns | minus: 1 %}
{% if loopindex == {{ numColumns }} - 1 %}
{% if loopindex == {{ numColumns | minus: 1 }} %}
How can I subtract one from numColumns in a conditional statement with the liquid templating engine?
You cannot use filter in liquid if expression.
You have to assign your calculation to a variable, then use it in your if tag.
{% assign calc = numColumns | minus: 1 %}
{% if loopindex == calc %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With