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