Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

handlebars-helper-repeat

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

handlebars-helper-repeat

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

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
863
decreased by-9.16%
Maintainers
1
Weekly downloads
 
Created
Source

handlebars-helper-repeat NPM version Build Status

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

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

Install with npm

npm i handlebars-helper-repeat --save

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>
  • template-helpers: Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or any engine that supports helper functions.
  • handlebars-helpers: 120+ Handlebars helpers in ~20 categories, for Assemble, YUI, Ghost or any Handlebars project. Includes helpers like {{i18}}, {{markdown}}, {{relative}}, {{extend}}, {{moment}}, and so on.

Contributing

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

Running tests

Install dev dependencies.

npm i -d && npm test

Authors

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb-cli on March 15, 2015.

Keywords

FAQs

Package last updated on 15 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc