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