mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
Split combined code blocks in If and Case examples
@@ -118,56 +118,78 @@ optionally, `elsif` and `else`) clause:
|
|||||||
{% if user %}
|
{% if user %}
|
||||||
Hello {{ user.name }}
|
Hello {{ user.name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
{% if user.name == 'tobi' %}
|
{% if user.name == 'tobi' %}
|
||||||
Hello tobi
|
Hello tobi
|
||||||
{% elsif user.name == 'bob' %}
|
{% elsif user.name == 'bob' %}
|
||||||
Hello bob
|
Hello bob
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
{% if user.name == 'tobi' or user.name == 'bob' %}
|
{% if user.name == 'tobi' or user.name == 'bob' %}
|
||||||
Hello tobi or bob
|
Hello tobi or bob
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
{% if user.name == 'bob' and user.age > 45 %}
|
{% if user.name == 'bob' and user.age > 45 %}
|
||||||
Hello old bob
|
Hello old bob
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
{% if user.name != 'tobi' %}
|
{% if user.name != 'tobi' %}
|
||||||
Hello non-tobi
|
Hello non-tobi
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
# Same as above
|
# Same as above
|
||||||
{% unless user.name == 'tobi' %}
|
{% unless user.name == 'tobi' %}
|
||||||
Hello non-tobi
|
Hello non-tobi
|
||||||
{% endunless %}
|
{% endunless %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
# Check if the user has a credit card
|
# Check if the user has a credit card
|
||||||
{% if user.creditcard != null %}
|
{% if user.creditcard != null %}
|
||||||
poor sob
|
poor sob
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
# Same as above
|
# Same as above
|
||||||
{% if user.creditcard %}
|
{% if user.creditcard %}
|
||||||
poor sob
|
poor sob
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
# Check for an empty array
|
# Check for an empty array
|
||||||
{% if user.payments == empty %}
|
{% if user.payments == empty %}
|
||||||
you never paid !
|
you never paid !
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
{% if user.age > 18 %}
|
{% if user.age > 18 %}
|
||||||
Login here
|
Login here
|
||||||
{% else %}
|
{% else %}
|
||||||
Sorry, you are too young
|
Sorry, you are too young
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
# array = 1,2,3
|
# array = 1,2,3
|
||||||
{% if array contains 2 %}
|
{% if array contains 2 %}
|
||||||
array includes 2
|
array includes 2
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
```liquid
|
||||||
# string = 'hello world'
|
# string = 'hello world'
|
||||||
{% if string contains 'hello' %}
|
{% if string contains 'hello' %}
|
||||||
string includes 'hello'
|
string includes 'hello'
|
||||||
@@ -213,9 +235,11 @@ has built-in support for such operations, using the `cycle` tag.
|
|||||||
{% cycle 'one', 'two', 'three' %}
|
{% cycle 'one', 'two', 'three' %}
|
||||||
{% cycle 'one', 'two', 'three' %}
|
{% cycle 'one', 'two', 'three' %}
|
||||||
{% cycle 'one', 'two', 'three' %}
|
{% cycle 'one', 'two', 'three' %}
|
||||||
|
```
|
||||||
|
|
||||||
will result in
|
will result in
|
||||||
|
|
||||||
|
```
|
||||||
one
|
one
|
||||||
two
|
two
|
||||||
three
|
three
|
||||||
@@ -233,9 +257,11 @@ the name of the group. This can even be a variable.
|
|||||||
{% cycle 'group 1': 'one', 'two', 'three' %}
|
{% cycle 'group 1': 'one', 'two', 'three' %}
|
||||||
{% cycle 'group 2': 'one', 'two', 'three' %}
|
{% cycle 'group 2': 'one', 'two', 'three' %}
|
||||||
{% cycle 'group 2': 'one', 'two', 'three' %}
|
{% cycle 'group 2': 'one', 'two', 'three' %}
|
||||||
|
```
|
||||||
|
|
||||||
will result in
|
will result in
|
||||||
|
|
||||||
|
```
|
||||||
one
|
one
|
||||||
two
|
two
|
||||||
one
|
one
|
||||||
|
|||||||
Reference in New Issue
Block a user