From 8a99a36ee9b487351187e4203dc8c888254406b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Tue, 4 Nov 2025 15:38:15 -0300 Subject: [PATCH] Enhance placeholder parsing functionality: Updated the TemplateService to support both dot and kebab-case formats for placeholders in HTML content. Improved regex patterns for parsing placeholders and custom blade components, ensuring better flexibility in template customization. --- app/Services/TemplateService.php | 12 ++++++------ .../components/custom/language-selector.blade.php | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/Services/TemplateService.php b/app/Services/TemplateService.php index 099f997..ee82bec 100644 --- a/app/Services/TemplateService.php +++ b/app/Services/TemplateService.php @@ -248,11 +248,11 @@ class TemplateService /** * Parse placeholders from HTML content - * Format: {type.field_name} + * Format: {type.field_name} or {type.field-name} */ public static function parsePlaceholders(string $html): array { - preg_match_all('/\{([a-z]+\.[a-z_]+)\}/i', $html, $matches); + preg_match_all('/\{([a-z]+\.[a-z][a-z_-]*)\}/i', $html, $matches); return array_unique($matches[1] ?? []); } @@ -289,8 +289,8 @@ class TemplateService $html = str_replace('{staticMenu}', $renderedStaticMenu, $html); } - // Handle custom blade components: {custom.component_name} - preg_match_all('/\{custom\.([a-z_]+)\}/i', $html, $customMatches); + // Handle custom blade components: {custom.component_name} or {custom.component-name} + preg_match_all('/\{custom\.([a-z][a-z_-]*)\}/i', $html, $customMatches); if (!empty($customMatches[0])) { foreach ($customMatches[0] as $index => $fullMatch) { $componentName = $customMatches[1][$index] ?? null; @@ -331,9 +331,9 @@ class TemplateService } } - // First, parse all placeholders in the format {type.field_name} + // First, parse all placeholders in the format {type.field_name} or {type.field-name} // Exclude custom.* from this regex to avoid double processing - preg_match_all('/\{([a-z]+\.[a-z_]+)\}/i', $html, $matches); + preg_match_all('/\{([a-z]+\.[a-z][a-z_-]*)\}/i', $html, $matches); $placeholders = array_unique($matches[1] ?? []); // Filter out custom.* placeholders as they're already handled above diff --git a/resources/views/components/custom/language-selector.blade.php b/resources/views/components/custom/language-selector.blade.php index 2f6883b..4589a54 100644 --- a/resources/views/components/custom/language-selector.blade.php +++ b/resources/views/components/custom/language-selector.blade.php @@ -11,7 +11,7 @@ $currentLanguage = $languages->firstWhere('code', $currentLang); @endphp @if($currentLanguage) - {{ $currentLanguage->flag ?? '' }} {{ strtoupper($currentLanguage->code) }} + {{ strtoupper($currentLanguage->code) }} @else {{ strtoupper($currentLang) }} @endif @@ -21,16 +21,13 @@ @endforeach - - + \ No newline at end of file