decrement
Subtracts one from a number. Sugar for | minus: 1.
{% assign remaining = remaining | decrement %}Syntax
{{ value | decrement }}Parameter
Description
value
The number to subtract one from
Return Value
Returns the value minus one. Identical to | minus: 1.
Examples
Count down remaining retries:
{% assign retries = 3 %}
{% while retries > 0 %}
{% http url: endpoint, method: "GET" as res %}
{% if res.ok %}{% break %}{% endif %}
{% assign retries = retries | decrement %}
{% endwhile %}Reduce stock in a payload:
Notes
Exactly
| minus: 1, including its coercion: non-numeric input yieldsNaN. Cast first withintegerif the input may be textNot the same as the
{% decrement %}tag. The filter returns a new value and leaves the variable alone; the tag subtracts one from the variable in place and outputs nothingSee also:
increment,minus, the{% decrement %}tag
Last updated