{{repeat}} handlebars helper, for duplicating a block of content n times.
JavaScript
Latest commit c8b6984 Jan 8, 2017 @jonschlinkert jonschlinkert 1.0.0
Permalink
Failed to load latest commit information.
.editorconfig run update Jan 8, 2017
.eslintrc.json run update Jan 8, 2017
.gitattributes lint Mar 15, 2015
.gitignore run update Jan 8, 2017
.travis.yml run update Jan 8, 2017
.verb.md generate docs Jan 8, 2017
LICENSE run update Jan 8, 2017
README.md generate docs Jan 8, 2017
bower.json 0.3.1 Mar 15, 2015
index.js refactor, clean up Jan 8, 2017
package.json 1.0.0 Jan 8, 2017
test.js refactor, clean up Jan 8, 2017

README.md

handlebars-helper-repeat NPM version NPM monthly downloads NPM total downloads Linux Build Status

Handlebars block helper for repeating whatever is inside the block n times.

Install

Install with npm:

$ npm install --save handlebars-helper-repeat

If you find a bug or have a feature request, please create an issue.

Usage

var helper = require('handlebars-helper-repeat');

Register with handlebars

var handlebars = require('handlebars');

// 2. register the helper, name it whatever you want
handlebars.registerHelper('repeat', helper);

// 3. register some partials
handlebars.registerPartial('button', '<button>{{text}}</button>');

// 4. use in templates
handlebars.compile('{{repeat 2}}{{> button }}{{/repeat}}')({text: 'Click me!'});
//=> '<button>Click me!</button><button>Click me!</button>'

Usage Examples

Private variables

A few private variables are exposed to blocks:

  • count the total number of blocks being generated
  • index the index of the current block
  • start the start number to use instead of zero. Basically index + start

Example:

{{#repeat count=2 start=17}}
  {{> button }}<span>{{@index}}</span>
{{else}}
  Nothing :(
{{/repeat}}

Results in something like:

<button>Click me!</button><span>17</span>
<button>Click me!</button><span>18</span>

Index

Output the index of the current block:

{{#repeat '2'}}
<div id="{{@index}}">
  {{> button }}
</div>
{{/repeat}}

Results in something like:

<div id="0">
  <button>Click me</button>
</div>
<div id="1">
  <button>Click me</button>
</div>

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v0.3.0, on January 08, 2017.