@vikaspotluri123 Even thought it might be a correct path to the file, modifying it changes nothing.
In the file: /var/www/ghost/versions/5.28.0/node_modules/@tryghost/email-service/lib/email-templates/template.hbs
I replaced the <a href="%%{unsubscribe_url}%%">
with <a href="https://my_custom_URL">
and restarted Ghost.
It didn’t help after the Ghost restart. The URL in the newsletter stayed the same. I decided to check if HTML in the opened newsletter corresponds to the one in template.hbs
. It has some differences, for example class names have random numbers, like: class="m_-216777451830...footer"
, where in the template it is just: <td class="footer">
.
I haven’t found any other similar template.hbs
file, but I made an assumption that email template is not generated by this file. I took a different route and modified the /versions/5.28.0/node_modules/@tryghost/email-service/lib/email-renderer.js
file which generates the %%{unsubscribe_url}%%
used in template.hbs
.
I replaced this function:
createUnsubscribeUrl(uuid, options = {}) {
const siteUrl = this.#urlUtils.urlFor('home', true);
const unsubscribeUrl = new URL(siteUrl);
unsubscribeUrl.pathname = `${unsubscribeUrl.pathname}/unsubscribe/`.replace('//', '/');
if (uuid) {
unsubscribeUrl.searchParams.set('uuid', uuid);
} else {
unsubscribeUrl.searchParams.set('preview', '1');
}
if (options.newsletterUuid) {
unsubscribeUrl.searchParams.set('newsletter', options.newsletterUuid);
}
if (options.comments) {
unsubscribeUrl.searchParams.set('comments', '1');
}
return unsubscribeUrl.href;
}
With a function that just returns my custom URL:
createUnsubscribeUrl(uuid, options = {}) {
const unsubscribeUrl = "https://my_custom_URL";
return unsubscribeUrl;
}
I reverted template.hbs
back to the original, restarted Ghost and even rebooted the server. However, the URL stayed the same, it still has uuid
and newsletter
parameters, even though I modified the function.
I’m totally confused now. Please, help me put custom unsubscribe link in the newsletter.