From: Mike Taylor Date: Thu, 28 Nov 2013 13:34:46 +0000 (+0000) Subject: Extend #first Handlebars helper with optional 'having' attribute. X-Git-Tag: 0.9.1~148^2~31 X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=commitdiff_plain;h=a18d8af3913ec2cbb2d32745ebd3c105aa931039 Extend #first Handlebars helper with optional 'having' attribute. --- diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 8e282a8..674bfff 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -119,7 +119,16 @@ Handlebars.registerHelper('json', function(obj) { Handlebars.registerHelper('first', function(items, options) { - return options.fn(items[0]); + var having = options.hash.having; + debug("#first checking for first item having '" + having + "'"); + for (var i in items) { + var item = items[i] + debug("considering item " + (+i+1) + " of " + items.length + " = '" + item[having] + "'"); + if (!having || item[having]) { + return options.fn(item); + } + } + return ""; });