Skip to content

Commit 01d1f08

Browse files
authored
Merge pull request TheAlgorithms#1057 from EricFromCanada/gh-pages-updates
Add additional documentation
2 parents 83ce52a + 58e6e41 commit 01d1f08

File tree

7 files changed

+94
-5
lines changed

7 files changed

+94
-5
lines changed

_basics/operators.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,28 @@ You can use multiple operators in a tag:
8787
```
8888

8989
`contains` can only search strings. You cannot use it to check for an object in an array of objects.
90+
91+
## Order of operations
92+
93+
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.
94+
95+
```liquid
96+
{% raw %}
97+
{% if true or false and false %}
98+
This evaluates to true, since the 'and' condition is checked first.
99+
{% endif %}
100+
{% endraw %}
101+
```
102+
103+
```liquid
104+
{% raw %}
105+
{% if true and false and false or true %}
106+
This evaluates to false, since the tags are checked like this:
107+
108+
true and (false and (false or true))
109+
true and (false and true)
110+
true and false
111+
false
112+
{% endif %}
113+
{% endraw %}
114+
```

_filters/first.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ Returns the first item of an array.
3636
3737
{{ my_array.first }}
3838
```
39+
40+
You can use `first` with dot notation when you need to use the filter inside a tag.
41+
42+
```liquid
43+
{% raw %}
44+
{% if my_array.first == "zebra" %}
45+
Here comes a zebra!
46+
{% endif %}
47+
{% endraw %}
48+
```

_filters/last.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ Returns the last item of an array.
3636
3737
{{ my_array.last }}
3838
```
39+
40+
You can use `last` with dot notation when you need to use the filter inside a tag.
41+
42+
```liquid
43+
{% raw %}
44+
{% if my_array.last == "tiger" %}
45+
There goes a tiger!
46+
{% endif %}
47+
{% endraw %}
48+
```

_filters/size.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: size
33
description: Liquid filter that returns the number of characters in a string or the number of items in an array.
44
---
55

6-
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.
6+
Returns the number of characters in a string or the number of items in an array.
77

88
<p class="code-label">Input</p>
99
```liquid
@@ -33,7 +33,7 @@ Returns the number of characters in a string or the number of items in an array.
3333
{{ my_array | size }}
3434
```
3535

36-
Using dot notation:
36+
You can use `size` with dot notation when you need to use the filter inside a tag.
3737

3838
```liquid
3939
{% raw %}

_filters/sort.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: sort
33
description: Liquid filter that sorts an array in case-sensitive order.
44
---
55

6-
Sorts items in an array by a property of an item in the array. The order of the sorted array is case-sensitive.
6+
Sorts items in an array in case-sensitive order.
77

88
<p class="code-label">Input</p>
99
```liquid
@@ -20,3 +20,14 @@ Sorts items in an array by a property of an item in the array. The order of the
2020
2121
{{ my_array | sort | join: ", " }}
2222
```
23+
24+
An optional parameter specifies which property of the array's items to use for sorting.
25+
26+
```liquid
27+
{% raw %}
28+
{% assign products_by_price = collection.products | sort: "price" %}
29+
{% for product in products_by_price %}
30+
<h4>{{ product.title }}</h4>
31+
{% endfor %}
32+
{% endraw %}
33+
```

_filters/sort_natural.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: sort_natural
33
description: Liquid filter that sorts an array in case-insensitive order.
44
---
55

6-
Sorts items in an array by a property of an item in the array.
6+
Sorts items in an array in case-insensitive order.
77

88
<p class="code-label">Input</p>
99
```liquid
@@ -16,5 +16,18 @@ Sorts items in an array by a property of an item in the array.
1616

1717
<p class="code-label">Output</p>
1818
```text
19-
giraffe, octopus, Sally Snake, zebra
19+
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
20+
21+
{{ my_array | sort_natural | join: ", " }}
22+
```
23+
24+
An optional parameter specifies which property of the array's items to use for sorting.
25+
26+
```liquid
27+
{% raw %}
28+
{% assign products_by_company = collection.products | sort_natural: "company" %}
29+
{% for product in products_by_company %}
30+
<h4>{{ product.title }}</h4>
31+
{% endfor %}
32+
{% endraw %}
2033
```

_tags/iteration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ Repeatedly executes a block of code. For a full list of attributes available wit
2323
hat shirt pants
2424
```
2525

26+
### else
27+
28+
Specifies a fallback case for a `for` loop which will run if the loop has zero length.
29+
30+
<p class="code-label">Input</p>
31+
```liquid
32+
{% raw %}
33+
{% for product in collection.products %}
34+
{{ product.title }}
35+
{% else %}
36+
The collection is empty.
37+
{% endfor %}
38+
{% endraw %}
39+
```
40+
41+
<p class="code-label">Output</p>
42+
```text
43+
The collection is empty.
44+
```
45+
2646
### break
2747

2848
Causes the loop to stop iterating when it encounters the `break` tag.

0 commit comments

Comments
 (0)