From d8f8a0c1fec335ae9e4887fca0bf9fdcbe6bee18 Mon Sep 17 00:00:00 2001 From: Romain Prieto Date: Sun, 16 Oct 2016 22:26:12 +1100 Subject: [PATCH] Add handy Handlebars helper to repeat a block N times Usage: {{#times 4}}hello{{/times} Can also use any variables in context, e.g. {{#times things.length}} --- src/output-website/template.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/output-website/template.js b/src/output-website/template.js index 67abf20..81faf60 100644 --- a/src/output-website/template.js +++ b/src/output-website/template.js @@ -51,6 +51,15 @@ exports.create = function(options) { return ret; }); + // utility helper + // execute the child block N times + handlebars.registerHelper('times', function(n, block) { + var accum = ''; + for(var i = 0; i < n; ++i) + accum += block.fn(i); + return accum; + }); + // utility helper // render the correct download path based on user options handlebars.registerHelper('download', function(file) {