p
This commit is contained in:
+24
-10
@@ -267,18 +267,32 @@ if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== tru
|
||||
preview = `<strong>Plantilla:</strong> ${msg.template_display_name || msg.template_name}`;
|
||||
if (msg.template_body) {
|
||||
let bodyPreview = msg.template_body;
|
||||
if (msg.template_parameters && Array.isArray(msg.template_parameters)) {
|
||||
// Reemplazar todas las variables en orden de aparición
|
||||
// Soporta tanto {{1}}, {{2}} como {{nombre_tema}}, {{fecha}}
|
||||
const regex = /\{\{[^\}]+\}\}/g;
|
||||
let paramIndex = 0;
|
||||
|
||||
if (msg.template_parameters) {
|
||||
const isArray = Array.isArray(msg.template_parameters);
|
||||
const isObject = typeof msg.template_parameters === 'object' && !isArray;
|
||||
|
||||
bodyPreview = bodyPreview.replace(regex, (match) => {
|
||||
const value = msg.template_parameters[paramIndex] || match;
|
||||
paramIndex++;
|
||||
return `<strong>${value}</strong>`;
|
||||
});
|
||||
if (isArray) {
|
||||
// Array indexado: [0] => "valor1", [1] => "valor2"
|
||||
const regex = /\{\{[^\}]+\}\}/g;
|
||||
let paramIndex = 0;
|
||||
|
||||
bodyPreview = bodyPreview.replace(regex, (match) => {
|
||||
const value = msg.template_parameters[paramIndex] || match;
|
||||
paramIndex++;
|
||||
return `<strong>${value}</strong>`;
|
||||
});
|
||||
} else if (isObject) {
|
||||
// Objeto asociativo: {nombre_tema: "valor1", fecha: "valor2"}
|
||||
const regex = /\{\{([^\}]+)\}\}/g;
|
||||
|
||||
bodyPreview = bodyPreview.replace(regex, (match, varName) => {
|
||||
const value = msg.template_parameters[varName] || match;
|
||||
return `<strong>${value}</strong>`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
preview += `<div class="message-preview">${bodyPreview}</div>`;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user