You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -246,6 +246,29 @@ The value of the `loop` attribute is not a pure expressions evaluation, and it d
246
246
247
247
So you don't need to declare all the available variables (in this case, the index is skipped), and the expressions after `in` doesn't need to be a local variable, it can be any expressions.
248
248
249
+
#### Loop meta
250
+
251
+
Inside a loop, you have access to a special `loop` object, which contains information about the loop currently being executed:
252
+
253
+
-`loop.index` - the current iteration of the loop (0 indexed)
254
+
-`loop.remaining` - number of iterations until the end (0 indexed)
255
+
-`loop.first` - boolean indicating if it's the first iteration
256
+
-`loop.last` - boolean indicating if it's the last iteration
257
+
-`loop.length` - total number of items
258
+
259
+
Example:
260
+
261
+
```html
262
+
<eachloop='item in [1,2,3]'>
263
+
<li>Item value: {{ item }}</li>
264
+
<li>Current iteration of the loop: {{ loop.index }}</li>
265
+
<li>Number of iterations until the end: {{ loop.remaining }} </li>
266
+
<li>This {{ loop.first ? 'is' : 'is not' }} the first iteration</li>
267
+
<li>This {{ loop.last ? 'is' : 'is not' }} the last iteration</li>
268
+
<li>Total number of items: {{ loop.length }}</li>
269
+
</each>
270
+
```
271
+
249
272
### Scopes
250
273
251
274
You can replace locals inside certain area wrapped in a `<scope>` tag. For example you can use it after [posthtml-include](https://github.com/posthtml/posthtml-include)
0 commit comments