diff --git a/ghost/core/core/server/services/comments/CommentsServiceEmails.js b/ghost/core/core/server/services/comments/CommentsServiceEmails.js index c5fbe9e784..252ec07473 100644 --- a/ghost/core/core/server/services/comments/CommentsServiceEmails.js +++ b/ghost/core/core/server/services/comments/CommentsServiceEmails.js @@ -15,7 +15,7 @@ class CommentsServiceEmails { this.urlService = urlService; this.urlUtils = urlUtils; - this.Handlebars = require('handlebars'); + this.Handlebars = require('handlebars').create(); } async notifyPostAuthors(comment) { diff --git a/ghost/email-service/lib/EmailRenderer.js b/ghost/email-service/lib/EmailRenderer.js index ad037c4b36..5c22ef0972 100644 --- a/ghost/email-service/lib/EmailRenderer.js +++ b/ghost/email-service/lib/EmailRenderer.js @@ -668,7 +668,7 @@ class EmailRenderer { } async renderTemplate(data) { - this.#handlebars = require('handlebars'); + this.#handlebars = require('handlebars').create(); // Helpers this.#handlebars.registerHelper('if', function (conditional, options) { diff --git a/ghost/staff-service/lib/StaffServiceEmails.js b/ghost/staff-service/lib/StaffServiceEmails.js index 75f1657d0b..516c84d31c 100644 --- a/ghost/staff-service/lib/StaffServiceEmails.js +++ b/ghost/staff-service/lib/StaffServiceEmails.js @@ -13,8 +13,9 @@ class StaffServiceEmails { this.urlUtils = urlUtils; this.labs = labs; - this.Handlebars = require('handlebars'); + this.Handlebars = require('handlebars').create(); this.registerPartials(); + this.registerHelpers(); } async notifyFreeMemberSignup({ @@ -478,10 +479,7 @@ class StaffServiceEmails { }); } - async renderHTML(templateName, data) { - const htmlTemplateSource = await fs.readFile(path.join(__dirname, './email-templates/', `${templateName}.hbs`), 'utf8'); - const htmlTemplate = this.Handlebars.compile(Buffer.from(htmlTemplateSource).toString()); - + registerHelpers() { this.Handlebars.registerHelper('eq', function (arg, value, options) { if (arg === value) { return options.fn(this); @@ -496,6 +494,11 @@ class StaffServiceEmails { } return array.slice(0,limit); }); + } + + async renderHTML(templateName, data) { + const htmlTemplateSource = await fs.readFile(path.join(__dirname, './email-templates/', `${templateName}.hbs`), 'utf8'); + const htmlTemplate = this.Handlebars.compile(Buffer.from(htmlTemplateSource).toString()); let sharedData = {}; if (data.recipient) {