Update storage.ts
This commit is contained in:
@@ -35,11 +35,12 @@ export const generateN8nCode = (template: EmailTemplate): string => {
|
||||
const hasVars = template.variables.length > 0;
|
||||
|
||||
return `// n8n Code Node - Template Populator
|
||||
// 1. Ensure the previous node (SQL) returns the template with 'full_html' column.
|
||||
// 2. Adjust the 'item.json.full_html' path if your SQL node output is different.
|
||||
// 1. Ensure the previous node (SQL) returns 'full_html' and 'subject'.
|
||||
// 2. Adjust path (item.json.full_html) if your SQL node output is different.
|
||||
|
||||
for (const item of items) {
|
||||
const templateHtml = item.json.full_html;
|
||||
const templateSubject = item.json.subject;
|
||||
|
||||
// Define your dynamic data here
|
||||
const replacements = {
|
||||
@@ -47,15 +48,21 @@ ${hasVars ? varsMap : ' // No variables detected in this template'}
|
||||
};
|
||||
|
||||
let finalHtml = templateHtml;
|
||||
let finalSubject = templateSubject;
|
||||
|
||||
// Perform replacement
|
||||
for (const [key, value] of Object.entries(replacements)) {
|
||||
// Replaces {{key}} globally
|
||||
finalHtml = finalHtml.replace(new RegExp('{{' + key + '}}', 'g'), value);
|
||||
// Replaces {{key}} globally in HTML and Subject
|
||||
const regex = new RegExp('{{' + key + '}}', 'g');
|
||||
finalHtml = finalHtml.replace(regex, value);
|
||||
if (finalSubject) {
|
||||
finalSubject = finalSubject.replace(regex, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Output the processed HTML
|
||||
// Output the processed content
|
||||
item.json.processed_html = finalHtml;
|
||||
item.json.processed_subject = finalSubject;
|
||||
}
|
||||
|
||||
return items;`;
|
||||
|
||||
Reference in New Issue
Block a user