Variables
The variable tag is used to create new variables and values.
Assign
Assign tag is used to assign a value to a variable.
When you assign a value to a variable, you will create a string.
{% assign profit = 100 %}
{{ profit }}
Capture
With this function you capture the string inside of the opening and closing tags and assigns it to a variable. Variables that you create using capture are stored as strings.
{% assign profit = 100 %}
{% capture profit_sentence %}
Your profit is {{ profit }}.
{% endcapture %}
{{ profit_sentence }}
Register
Registers are used to store numbers and / or result of a calculation. This allows you to print the value or start some further calculations with the register.
Registers are local variables with some unique characteristics. Registers are created by using a dollar sign $ with a number from 0 to 39.
registers
Let's assume that revenue is 200.
Let's assume that cost is -100.
We want to add up two values, revenue and cost. Therefore, we store both values in 1 register ($0). By printing $0, we automatically see the value the register contains.
{% $0+ revenue %}
{% $0+ cost %}
{{ $0 }}
It is possible to show the variables that were added by putting an equal sign.
Revenue: {% =$0+ revenue %}
Cost: {% =$0+ cost %}
Profit: {{ $0 }}
Cost: -100.00
Profit: 100.0
registers with input
Register can be used in combination with an input tag.
{% $0+input custom.asset.value %}
{{ $0 }}

Updated over 2 years ago