mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
feat: replace template variables with values
Co-authored-by: Mythie <me@lucasjamessmith.me>
This commit is contained in:
committed by
Mythie
parent
da16f1ee07
commit
345343f4b5
20
packages/lib/utils/render-custom-email-template.ts
Normal file
20
packages/lib/utils/render-custom-email-template.ts
Normal file
@ -0,0 +1,20 @@
|
||||
export const renderCustomEmailTemplate = <T extends Record<string, string>>(
|
||||
template: string,
|
||||
variables: T,
|
||||
): string => {
|
||||
let t = template;
|
||||
|
||||
Object.entries(variables).forEach((entry) => {
|
||||
const [key, value] = entry;
|
||||
|
||||
const placeholder = `{${key}}`;
|
||||
|
||||
const re = new RegExp(placeholder, 'g');
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(variables, key)) {
|
||||
t = t.replace(re, String(value));
|
||||
}
|
||||
});
|
||||
|
||||
return t;
|
||||
};
|
||||
Reference in New Issue
Block a user