Enhance Template Processing and Cleanup: Updated the ImportHtmlTemplates command to skip additional custom tokens during HTML processing and added a cleanup step to remove leftover tokens from the data array. Improved the TemplateService to replace legacy tokens in HTML, ensuring better template integrity during imports.

This commit is contained in:
Ümit Tunç
2025-12-29 09:39:21 +03:00
parent f4603456b1
commit 9d601cafda
2 changed files with 21 additions and 2 deletions
+13 -2
View File
@@ -268,8 +268,8 @@ class ImportHtmlTemplates extends Command
if (in_array(strtolower($parent->nodeName), ['script', 'style', 'noscript', 'iframe'])) continue; if (in_array(strtolower($parent->nodeName), ['script', 'style', 'noscript', 'iframe'])) continue;
$textContent = trim($textNode->textContent); $textContent = trim($textNode->textContent);
// Özel tokenlarımızı atla // Özel tokenlarımızı atla (___SPECIAL_, ___SETTING_, ___CUSTOM_)
if (str_contains($textContent, '___SPECIAL_') || str_contains($textContent, '___SETTING_')) continue; if (str_contains($textContent, '___SPECIAL_') || str_contains($textContent, '___SETTING_') || str_contains($textContent, '___CUSTOM_')) continue;
if (str_starts_with($textContent, '{') && str_ends_with($textContent, '}')) continue; if (str_starts_with($textContent, '{') && str_ends_with($textContent, '}')) continue;
if (mb_strlen($textContent) < 2) continue; if (mb_strlen($textContent) < 2) continue;
@@ -297,6 +297,17 @@ class ImportHtmlTemplates extends Command
$html = str_replace('___CUSTOM_LANGUAGE___', '{custom.language-selector}', $html); $html = str_replace('___CUSTOM_LANGUAGE___', '{custom.language-selector}', $html);
$html = str_replace('___SETTING_LANGUAGES___', '{custom.language-selector}', $html); $html = str_replace('___SETTING_LANGUAGES___', '{custom.language-selector}', $html);
// Clean default_data from any leftover tokens
foreach ($data as $key => $value) {
if (is_string($value) && (
str_contains($value, '___CUSTOM_') ||
str_contains($value, '___SPECIAL_') ||
str_contains($value, '___SETTING_')
)) {
unset($data[$key]);
}
}
return ['html' => $html, 'data' => $data]; return ['html' => $html, 'data' => $data];
} }
+8
View File
@@ -318,6 +318,14 @@ class TemplateService
*/ */
public static function replacePlaceholders(string $html, array $data, ?Model $model = null, array $defaultData = []): string public static function replacePlaceholders(string $html, array $data, ?Model $model = null, array $defaultData = []): string
{ {
// Legacy/Import artifact fix: Replace ___CUSTOM_...___ tokens if they exist in DB
// These tokens might be leftover from import process if str_replace didn't catch them
$html = str_replace('___SPECIAL_MENU___', '{custom.menu}', $html);
$html = str_replace('___CUSTOM_MENU___', '{custom.menu}', $html);
$html = str_replace('___CUSTOM_NAVBAR___', '{custom.navbar}', $html);
$html = str_replace('___CUSTOM_LANGUAGE___', '{custom.language-selector}', $html);
$html = str_replace('___SETTING_LANGUAGES___', '{custom.language-selector}', $html);
// Handle special {page.content} placeholder - Sayfa/model içeriğini gösterir // Handle special {page.content} placeholder - Sayfa/model içeriğini gösterir
if (str_contains($html, '{page.content}')) { if (str_contains($html, '{page.content}')) {
$pageContent = ''; $pageContent = '';