1 unstable release
0.1.0 | Aug 10, 2021 |
---|
#554 in Template engine
10KB
97 lines
handlebars-repeat
This crate provides a handlebars helper function which repeats a block
a given number of times (the count
). For example:
{{#repeat 3}}
hi
{{/repeat}}
Produces:
hi
hi
hi
Local Variables
Within the repeated block, there are three local variables in addition to the standard context:
@index
is an integer indicating the index of the current repetition.@first
is a boolean indicating whether this is the first repetation.@last
is a boolean indicating whether this is the last repetation.
For example:
{{#repeat 3}}
Index: {{@index}} (first: {{@first}}; last: {{@last}})
{{/repeat}}
Produces:
Index: 0 (first: true; last: false)
Index: 1 (first: false; last: false)
Index: 2 (first: false; last: true)
Inverse Block
Like the standard each
helper function, repeat
can specify an inverse
block which will be rendered when count == 0
. For example:
{{#repeat 0}}
foo
{{else}}
bar
{{/repeat}}
Produces:
bar
License: MIT
Dependencies
~2.8–4MB
~80K SLoC