Skip to content

Commit 86ec945

Browse files
AntVil0xTim
andauthored
add documentation for index-variable (#1164)
<!-- 🚀 Thank you for contributing! --> <!-- Describe your changes clearly and use examples if possible. --> Document `#(index)` variable <!-- When this PR is merged, the title and body will be --> <!-- used to generate a release automatically. --> --------- Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
1 parent 8ffd14a commit 86ec945

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

docs/4.0/leaf/overview.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ Planets:
154154
- Mars
155155
```
156156

157+
Leaf also offers an index-entry option for iteration which allows you to access the index in the loop:
158+
159+
```leaf
160+
Planets:
161+
<ul>
162+
#for(index, planet in planets):
163+
<li>#(index + 1) #(planet)</li>
164+
#endfor
165+
</ul>
166+
```
167+
168+
This would result in:
169+
170+
```
171+
Planets:
172+
- 1 Venus
173+
- 2 Earth
174+
- 3 Mars
175+
```
176+
157177
### Extending templates
158178

159179
Leaf’s `#extend` tag allows you to copy the contents of one template into another. When using this, you should always omit the template file's .leaf extension.

0 commit comments

Comments
 (0)