From 2c64ac3dd810b27e17cf37673cde3e7627ea532d Mon Sep 17 00:00:00 2001 From: matt Date: Tue, 8 Feb 2022 20:20:23 +0000 Subject: [PATCH] Added handlebars equality helper --- app.js | 4 +++- lib/handlebarsHelpers.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 lib/handlebarsHelpers.js diff --git a/app.js b/app.js index aa12997..b86f79c 100644 --- a/app.js +++ b/app.js @@ -12,6 +12,7 @@ const serveStatic = require('serve-static'); // Import user defined modules const DatabaseConnectionPool = require('./lib/DatabaseConnectionPool'); +const hbsHelpers = require('./lib/handlebarsHelpers.js'); const importJSON = require('./lib/importJSON'); @@ -53,7 +54,8 @@ async function main() { app.engine( 'hbs', engine({ - extname: '.hbs' + extname: '.hbs', + helpers: hbsHelpers }) ); app.set('view engine', 'hbs'); diff --git a/lib/handlebarsHelpers.js b/lib/handlebarsHelpers.js new file mode 100644 index 0000000..88bd8f2 --- /dev/null +++ b/lib/handlebarsHelpers.js @@ -0,0 +1,6 @@ +const helpers = {}; + +helpers.eq = (arg1, arg2, options) => + arg1 == arg2 ? options.fn(this) : options.inverse(this); + +module.exports = helpers;