-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
28 lines (22 loc) · 842 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Handlebars from "handlebars";
import mongoose from "mongoose";
function registerHelpers() {
// Used to conditionally render a portion of HTML if two values are equal
Handlebars.registerHelper("ifEquals", (arg1, arg2, options) => {
return arg1 === arg2 ? options.fn(this) : options.inverse(this);
});
Handlebars.registerHelper("ifEqualsID", function (arg1, arg2, options) {
let context = this; //
if (arg1 instanceof mongoose.Types.ObjectId) {
arg1 = arg1.toString();
}
if (arg2 instanceof mongoose.Types.ObjectId) {
arg2 = arg2.toString();
}
return arg1 === arg2 ? options.fn(context) : options.inverse(context);
});
Handlebars.registerHelper("ifNotEqual", (a, b, options) => {
return a !== b ? options.fn(this) : options.inverse(this);
});
}
export { registerHelpers };