Assigning Variables
Variables are saved and reusable values which can be referenced by other tags and objects within the view.
Liquid Input
{% assign name = "John" %}
{% assign unread_messages = 3 %}
{% if unread_messages > 0 %}
Hello {{ name }}, you have {{ unread_messages }} unread messages!
{% endif %}
HTML Output
Hello John, you have 3 unread messages!
Capturing Variables
The capture
tag assigns the content between the capture
and endcapture
tags to a variable. Content inside the tags can reference other variables you've set, or standard variables provided by Sonadier.
Liquid Input
{% assign unread_messages = 3 %}
{% capture message %}
{% if unread_messages > 0 %}
Hello {{ user.name }}, you have {{ unread_messages }} unread messages!
{% endif %}
{% endcapture %}
<span title="{{message}}">{{message}}</span>
HTML Output
<span title="Hello John, you have 3 unread messages!">
Hello John, you have 3 unread messages!
</span>