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.

This commit is contained in:
Ümit Tunç
2025-11-04 15:38:15 -03:00
parent 45534be05e
commit 8a99a36ee9
2 changed files with 9 additions and 12 deletions
+6 -6
View File
@@ -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
@@ -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 @@
<li class="nav-item">
<a class="dropdown-item hover:!text-[#747ed1] {{ $language->code === $currentLang ? 'active' : '' }}"
href="{{ route('language.switch', $language->code) }}">
{{ $language->flag ?? '' }} {{ strtoupper($language->code) }}
{{ strtoupper($language->code) }}
</a>
</li>
@endforeach
</ul>
</li>
<li class="nav-item"><a class="nav-link" data-bs-toggle="offcanvas" data-bs-target="#offcanvas-info"><i class="uil uil-info-circle before:content-['\eb99'] !text-[1.1rem]"></i></a></li>
<li class="nav-item xl:!hidden lg:!hidden">
<button class="hamburger offcanvas-nav-btn"><span></span></button>
</li>
</ul>
<!-- /.navbar-nav -->
</div>