From 30821dbcbbf5a045345cdcb4334a8a63fb4f9b4a Mon Sep 17 00:00:00 2001 From: Yashashvi Dave Date: Fri, 14 Jun 2019 18:06:17 +0530 Subject: [PATCH] handlebars: Register `if_equal` handlebar helper. `if_equal` execute conditional code if both conditions are equal in templates. --- static/js/templates.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/static/js/templates.js b/static/js/templates.js index 1633039e09..b000bb90f7 100644 --- a/static/js/templates.js +++ b/static/js/templates.js @@ -75,6 +75,15 @@ Handlebars.registerHelper('unless_a_not_b', function () { return options.fn(this); }); +Handlebars.registerHelper('if_equal', function () { + // Execute conditional code if both values are equal + var options = arguments[arguments.length - 1]; + if (arguments[0] === arguments[1]) { + return options.fn(this); + } + return options.inverse(this); +}); + Handlebars.registerHelper('if_not_a_or_b_and_not_c', function () { var options = arguments[arguments.length - 1]; if (arguments[0] === false || arguments[1] === true && arguments[2] === false) {