Merge pull request #229 from stedman/patch-1

docs: Add hashes to `for` tag documentation
This commit is contained in:
Jun Yang
2020-05-23 01:56:13 +08:00
committed by GitHub
+18 -1
View File
@@ -8,7 +8,7 @@ Iteration tags run blocks of code repeatedly.
### for...in
Repeatedly executes a block of code. For a full list of attributes available within a `for` loop.
Repeatedly executes a block of code. For a full list of attributes available within a `for` loop, see [forloop](#forloop).
Input
```liquid
@@ -22,6 +22,23 @@ Output
hat shirt pants
```
For loops can iterate over arrays, hashes, and [ranges of integers](#range).
When iterating a hash, item[0] contains the key, and item[1] contains the value:
Input
```liquid
{% for item in hash %}
* {{ item[0] }}: {{ item[1] }}
{% endfor %}
```
Output
```text
* key1: value1
* key2: value2
```
### else
Specifies a fallback case for a `for` loop which will run if the loop has zero length.