Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/helpers/handlebars-helper-repeat

{{repeat}} handlebars helper, for duplicating a block of content n times.
https://github.com/helpers/handlebars-helper-repeat

engine handlebars helper javascript jonschlinkert node nodejs repeat repeat-string template

Last synced: about 1 month ago
JSON representation

{{repeat}} handlebars helper, for duplicating a block of content n times.

Awesome Lists containing this project

README

        

# handlebars-helper-repeat [![NPM version](https://img.shields.io/npm/v/handlebars-helper-repeat.svg?style=flat)](https://www.npmjs.com/package/handlebars-helper-repeat) [![NPM monthly downloads](https://img.shields.io/npm/dm/handlebars-helper-repeat.svg?style=flat)](https://npmjs.org/package/handlebars-helper-repeat) [![NPM total downloads](https://img.shields.io/npm/dt/handlebars-helper-repeat.svg?style=flat)](https://npmjs.org/package/handlebars-helper-repeat) [![Linux Build Status](https://img.shields.io/travis/helpers/handlebars-helper-repeat.svg?style=flat&label=Travis)](https://travis-ci.org/helpers/handlebars-helper-repeat)

> Handlebars block helper for repeating whatever is inside the block _n_ times.

Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save handlebars-helper-repeat
```

If you find a bug or have a feature request, [please create an issue](https://github.com/helpers/handlebars-helper-repeat/issues).

## Usage

```js
const repeat = require('handlebars-helper-repeat');
handlebars.registerHelper('repeat', repeat);
```

## Register with handlebars

```js
const handlebars = require('handlebars');

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

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

// 4. use in templates
const fn = handlebars.compile('{{#repeat 2}}{{> button }}{{/repeat}}');

console.log(fn({text: 'Click me!'}));
//=> 'Click me!Click me!'
```

## 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:

```handlebars
{{#repeat count=2 start=17}}
{{> button }}{{@index}}
{{else}}
Nothing :(
{{/repeat}}
```
Results in something like:

```html
Click me!17
Click me!18
```

**Index**

Output the index of the current block:

```handlebars
{{#repeat 2}}

{{> button }}

{{/repeat}}
```

Results in something like:

```html

Click me

Click me

```

## About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Related projects

You might also be interested in these projects:

* [handlebars-helpers](https://www.npmjs.com/package/handlebars-helpers): More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… [more](https://github.com/helpers/handlebars-helpers) | [homepage](https://github.com/helpers/handlebars-helpers "More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.")
* [repeat-string](https://www.npmjs.com/package/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. | [homepage](https://github.com/jonschlinkert/repeat-string "Repeat the given string n times. Fastest implementation for repeating a string.")
* [template-helpers](https://www.npmjs.com/package/template-helpers): Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… [more](https://github.com/jonschlinkert/template-helpers) | [homepage](https://github.com/jonschlinkert/template-helpers "Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or any engine that supports helper functions.")

### Author

**Jon Schlinkert**

* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)

### License

Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 23, 2018._