Merge pull request #1057 from EricFromCanada/gh-pages-updates

Add additional documentation
This commit is contained in:
Adam Hollett
2019-08-30 10:09:55 -04:00
committed by GitHub
7 changed files with 94 additions and 5 deletions

View File

@@ -87,3 +87,28 @@ You can use multiple operators in a tag:
```
`contains` can only search strings. You cannot use it to check for an object in an array of objects.
## Order of operations
In tags with more than one `and` or `or` operator, operators are checked in order *from right to left*. You cannot change the order of operations using parentheses — parentheses are invalid characters in Liquid and will prevent your tags from working.
```liquid
{% raw %}
{% if true or false and false %}
This evaluates to true, since the 'and' condition is checked first.
{% endif %}
{% endraw %}
```
```liquid
{% raw %}
{% if true and false and false or true %}
This evaluates to false, since the tags are checked like this:
true and (false and (false or true))
true and (false and true)
true and false
false
{% endif %}
{% endraw %}
```

View File

@@ -36,3 +36,13 @@ Returns the first item of an array.
{{ my_array.first }}
```
You can use `first` with dot notation when you need to use the filter inside a tag.
```liquid
{% raw %}
{% if my_array.first == "zebra" %}
Here comes a zebra!
{% endif %}
{% endraw %}
```

View File

@@ -36,3 +36,13 @@ Returns the last item of an array.
{{ my_array.last }}
```
You can use `last` with dot notation when you need to use the filter inside a tag.
```liquid
{% raw %}
{% if my_array.last == "tiger" %}
There goes a tiger!
{% endif %}
{% endraw %}
```

View File

@@ -3,7 +3,7 @@ title: size
description: Liquid filter that returns the number of characters in a string or the number of items in an array.
---
Returns the number of characters in a string or the number of items in an array. `size` can also be used with dot notation (for example, `{% raw %}{{ my_string.size }}{% endraw %}`). This allows you to use `size` inside tags such as conditionals.
Returns the number of characters in a string or the number of items in an array.
<p class="code-label">Input</p>
```liquid
@@ -33,7 +33,7 @@ Returns the number of characters in a string or the number of items in an array.
{{ my_array | size }}
```
Using dot notation:
You can use `size` with dot notation when you need to use the filter inside a tag.
```liquid
{% raw %}

View File

@@ -3,7 +3,7 @@ title: sort
description: Liquid filter that sorts an array in case-sensitive order.
---
Sorts items in an array by a property of an item in the array. The order of the sorted array is case-sensitive.
Sorts items in an array in case-sensitive order.
<p class="code-label">Input</p>
```liquid
@@ -20,3 +20,14 @@ Sorts items in an array by a property of an item in the array. The order of the
{{ my_array | sort | join: ", " }}
```
An optional parameter specifies which property of the array's items to use for sorting.
```liquid
{% raw %}
{% assign products_by_price = collection.products | sort: "price" %}
{% for product in products_by_price %}
<h4>{{ product.title }}</h4>
{% endfor %}
{% endraw %}
```

View File

@@ -3,7 +3,7 @@ title: sort_natural
description: Liquid filter that sorts an array in case-insensitive order.
---
Sorts items in an array by a property of an item in the array.
Sorts items in an array in case-insensitive order.
<p class="code-label">Input</p>
```liquid
@@ -16,5 +16,18 @@ Sorts items in an array by a property of an item in the array.
<p class="code-label">Output</p>
```text
giraffe, octopus, Sally Snake, zebra
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort_natural | join: ", " }}
```
An optional parameter specifies which property of the array's items to use for sorting.
```liquid
{% raw %}
{% assign products_by_company = collection.products | sort_natural: "company" %}
{% for product in products_by_company %}
<h4>{{ product.title }}</h4>
{% endfor %}
{% endraw %}
```

View File

@@ -23,6 +23,26 @@ Repeatedly executes a block of code. For a full list of attributes available wit
hat shirt pants
```
### else
Specifies a fallback case for a `for` loop which will run if the loop has zero length.
<p class="code-label">Input</p>
```liquid
{% raw %}
{% for product in collection.products %}
{{ product.title }}
{% else %}
The collection is empty.
{% endfor %}
{% endraw %}
```
<p class="code-label">Output</p>
```text
The collection is empty.
```
### break
Causes the loop to stop iterating when it encounters the `break` tag.