Documentation for the #if-any helper.
[mkws-moved-to-github.git] / tools / htdocs / mkws.js
index 43b2204..769c574 100644 (file)
@@ -124,12 +124,28 @@ Handlebars.registerHelper('attr', function(attrName) {
 });
 
 
+/*
+ * Use as follows: {{#if-any NAME1 having="NAME2"}}
+ * Applicable when NAME1 is the name of an array
+ * The guarded code runs only if at least one element of the NAME1
+ * array has a subelement called NAME2.
+ */
+Handlebars.registerHelper('if-any', function(items, options) {
+    var having = options.hash.having;
+    for (var i in items) {
+       var item = items[i]
+       if (!having || item[having]) {
+           return options.fn(this);
+       }
+    }
+    return "";
+});
+
+
 Handlebars.registerHelper('first', function(items, options) {
     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);
        }