mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Migrated from home v5
+40
-11
@@ -36,7 +36,7 @@ h2. Comments
|
|||||||
Comment is the simplest tag. It just swallows content.
|
Comment is the simplest tag. It just swallows content.
|
||||||
|
|
||||||
<pre><code>
|
<pre><code>
|
||||||
Hi tobi {% comment %} you stink {% endcomment %}
|
We made 1 million dollars {% comment %} in losses {% endcomment %} this year
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
h2. If / Else
|
h2. If / Else
|
||||||
@@ -46,21 +46,36 @@ in the if.
|
|||||||
|
|
||||||
<pre><code>
|
<pre><code>
|
||||||
{% if user %}
|
{% if user %}
|
||||||
Hi {{ user.name }}
|
Hello {{ user.name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if user.name == 'tobi' %}
|
{% if user.name == 'tobi' %}
|
||||||
hi tobi
|
Hello tobi
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if user.name == 'tobi' or user.name == 'bob' %}
|
||||||
|
Hello tobi or bob
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if user.name == 'bob' and user.age > 45 %}
|
||||||
|
Hello old bob
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if user.name != 'tobi' %}
|
{% if user.name != 'tobi' %}
|
||||||
hi non-tobi
|
Hello non-tobi
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
# Check if the user has a credit card
|
||||||
{% if user.creditcard == null %}
|
{% if user.creditcard == null %}
|
||||||
poor sob
|
poor sob
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
# Same as above
|
||||||
|
{% if user.creditcard %}
|
||||||
|
poor sob
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
# Check for an empty array
|
||||||
{% if user.payments == empty %}
|
{% if user.payments == empty %}
|
||||||
you never paid !
|
you never paid !
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -72,6 +87,16 @@ in the if.
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
|
# array = 1,2,3
|
||||||
|
{% if array includes 2 %}
|
||||||
|
array includes 2
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
# string = 'hello world'
|
||||||
|
{% if string includes 'hello' %}
|
||||||
|
string includes 'hello'
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
h2. Case Statement
|
h2. Case Statement
|
||||||
|
|
||||||
If you need more than one condition you can use the Case Statement
|
If you need more than one condition you can use the Case Statement
|
||||||
@@ -80,11 +105,10 @@ If you need more than one condition you can use the Case Statement
|
|||||||
{% case condition %}
|
{% case condition %}
|
||||||
{% when 1 %}
|
{% when 1 %}
|
||||||
hit 1
|
hit 1
|
||||||
{% when 2 %}
|
{% when 2 or 3 %}
|
||||||
|
hit 2 or 3
|
||||||
hit 2
|
|
||||||
{% else %}
|
{% else %}
|
||||||
elseblock
|
... else ...
|
||||||
{% endcase %}
|
{% endcase %}
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
@@ -163,9 +187,8 @@ During every for loop there are following helper variables available for extra s
|
|||||||
|
|
||||||
There are several attributes you can use to influence which items you receive in your loop
|
There are several attributes you can use to influence which items you receive in your loop
|
||||||
|
|
||||||
*limit* lets you restrict how many items you get
|
*limit:int* lets you restrict how many items you get
|
||||||
*offset* lets you start the collection with the nth item.
|
*offset:int* lets you start the collection with the nth item.
|
||||||
*descending* Reverses the loop
|
|
||||||
|
|
||||||
<pre><code>
|
<pre><code>
|
||||||
# array = [1,2,3,4,5,6]
|
# array = [1,2,3,4,5,6]
|
||||||
@@ -175,6 +198,12 @@ There are several attributes you can use to influence which items you receive in
|
|||||||
# results in 3,4
|
# results in 3,4
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
|
Reversing the loop
|
||||||
|
|
||||||
|
<pre><code>
|
||||||
|
{% for item in collection reversed %} {{item}} {% endfor %}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
Instead of looping over an existing collection, you can define a range of numbers to loop through. The range can be defined by both literal and variable numbers:
|
Instead of looping over an existing collection, you can define a range of numbers to loop through. The range can be defined by both literal and variable numbers:
|
||||||
|
|
||||||
<pre><code>
|
<pre><code>
|
||||||
|
|||||||
Reference in New Issue
Block a user