diff --git a/app/Filament/Admin/Resources/FooterTemplates/Schemas/FooterTemplateForm.php b/app/Filament/Admin/Resources/FooterTemplates/Schemas/FooterTemplateForm.php index 20dd3f5..fe9a753 100644 --- a/app/Filament/Admin/Resources/FooterTemplates/Schemas/FooterTemplateForm.php +++ b/app/Filament/Admin/Resources/FooterTemplates/Schemas/FooterTemplateForm.php @@ -29,6 +29,13 @@ class FooterTemplateForm ->maxLength(255) ->columnSpanFull(), + // Placeholder Picker Component + View::make('components.placeholder-picker') + ->viewData([ + 'fieldName' => 'html_content', + ]) + ->columnSpanFull(), + CodeEditor::make('html_content') ->label(__('footer-templates.field_html_content')) ->required() diff --git a/app/Filament/Admin/Resources/HeaderTemplates/Schemas/HeaderTemplateForm.php b/app/Filament/Admin/Resources/HeaderTemplates/Schemas/HeaderTemplateForm.php index c99aed3..2519047 100644 --- a/app/Filament/Admin/Resources/HeaderTemplates/Schemas/HeaderTemplateForm.php +++ b/app/Filament/Admin/Resources/HeaderTemplates/Schemas/HeaderTemplateForm.php @@ -28,6 +28,13 @@ class HeaderTemplateForm ->maxLength(255) ->columnSpanFull(), + // Placeholder Picker Component + View::make('components.placeholder-picker') + ->viewData([ + 'fieldName' => 'html_content', + ]) + ->columnSpanFull(), + CodeEditor::make('html_content') ->label(__('header-templates.field_html_content')) ->required() diff --git a/app/Filament/Admin/Resources/MenuTemplates/Schemas/MenuTemplateForm.php b/app/Filament/Admin/Resources/MenuTemplates/Schemas/MenuTemplateForm.php index b16a743..a7bca8b 100644 --- a/app/Filament/Admin/Resources/MenuTemplates/Schemas/MenuTemplateForm.php +++ b/app/Filament/Admin/Resources/MenuTemplates/Schemas/MenuTemplateForm.php @@ -25,6 +25,13 @@ class MenuTemplateForm ->maxLength(255) ->columnSpanFull(), + // Placeholder Picker Component + View::make('components.placeholder-picker') + ->viewData([ + 'fieldName' => 'html_content', + ]) + ->columnSpanFull(), + CodeEditor::make('html_content') ->label(__('menu-templates.field_html_content')) ->required() diff --git a/app/Filament/Admin/Resources/SectionTemplates/Schemas/SectionTemplateForm.php b/app/Filament/Admin/Resources/SectionTemplates/Schemas/SectionTemplateForm.php index 2849380..e2f0d2f 100644 --- a/app/Filament/Admin/Resources/SectionTemplates/Schemas/SectionTemplateForm.php +++ b/app/Filament/Admin/Resources/SectionTemplates/Schemas/SectionTemplateForm.php @@ -28,6 +28,13 @@ class SectionTemplateForm ->maxLength(255) ->columnSpanFull(), + // Placeholder Picker Component + View::make('components.placeholder-picker') + ->viewData([ + 'fieldName' => 'html_content', + ]) + ->columnSpanFull(), + CodeEditor::make('html_content') ->label(__('section-templates.field_html_content')) ->required() diff --git a/app/Services/TemplateService.php b/app/Services/TemplateService.php index 67a4790..119eea0 100644 --- a/app/Services/TemplateService.php +++ b/app/Services/TemplateService.php @@ -39,6 +39,11 @@ class TemplateService [$type, $name] = $parts; + // Skip custom.* placeholders - they are blade components, not form fields + if ($type === 'custom') { + continue; + } + $label = str($name)->title()->replace('_', ' ')->toString(); // Get existing value from existingData if provided @@ -268,6 +273,7 @@ class TemplateService * Replace placeholders in HTML with actual data * Supports both {text.title} and {{text.title}} formats * Also supports {menu} and {staticMenu} placeholders for menu rendering + * Also supports {custom.component_name} for custom blade components */ public static function replacePlaceholders(string $html, array $data): string { @@ -283,10 +289,39 @@ class TemplateService $html = str_replace('{staticMenu}', $renderedStaticMenu, $html); } + // Handle custom blade components: {custom.component_name} + preg_match_all('/\{custom\.([a-z_]+)\}/i', $html, $customMatches); + if (!empty($customMatches[0])) { + foreach ($customMatches[0] as $index => $fullMatch) { + $componentName = $customMatches[1][$index] ?? null; + if ($componentName) { + $viewPath = "components.custom.{$componentName}"; + if (view()->exists($viewPath)) { + try { + $renderedComponent = view($viewPath)->render(); + $html = str_replace($fullMatch, $renderedComponent, $html); + } catch (\Exception $e) { + // If rendering fails, remove the placeholder or show error + $html = str_replace($fullMatch, "", $html); + } + } else { + // Component doesn't exist, remove placeholder or show notice + $html = str_replace($fullMatch, "", $html); + } + } + } + } + // First, parse all placeholders in the format {type.field_name} + // Exclude custom.* from this regex to avoid double processing preg_match_all('/\{([a-z]+\.[a-z_]+)\}/i', $html, $matches); $placeholders = array_unique($matches[1] ?? []); + // Filter out custom.* placeholders as they're already handled above + $placeholders = array_filter($placeholders, function($placeholder) { + return !str_starts_with($placeholder, 'custom.'); + }); + // Replace each placeholder foreach ($placeholders as $placeholder) { // Try to find the value in data with various key formats diff --git a/lang/en/placeholder-picker.php b/lang/en/placeholder-picker.php new file mode 100644 index 0000000..4ceb7e7 --- /dev/null +++ b/lang/en/placeholder-picker.php @@ -0,0 +1,33 @@ + 'Placeholder Variables', + 'click_to_insert' => 'Click to insert into editor', + 'special_placeholders' => 'Special Placeholders', + + // Placeholder Types + 'type_text' => 'Text', + 'type_email' => 'Email', + 'type_url' => 'URL', + 'type_tel' => 'Telephone', + 'type_number' => 'Number', + 'type_textarea' => 'Textarea', + 'type_richtext' => 'Rich Text', + 'type_markdown' => 'Markdown', + 'type_code' => 'Code', + 'type_date' => 'Date', + 'type_datetime' => 'Date & Time', + 'type_time' => 'Time', + 'type_image' => 'Image', + 'type_images' => 'Images (Multiple)', + 'type_file' => 'File', + 'type_files' => 'Files (Multiple)', + 'type_select' => 'Select', + 'type_multiselect' => 'Multi Select', + 'type_checkbox' => 'Checkbox', + 'type_radio' => 'Radio', + 'type_toggle' => 'Toggle', + 'type_color' => 'Color', + 'type_tags' => 'Tags', +]; + diff --git a/lang/tr/placeholder-picker.php b/lang/tr/placeholder-picker.php new file mode 100644 index 0000000..dd95440 --- /dev/null +++ b/lang/tr/placeholder-picker.php @@ -0,0 +1,33 @@ + 'Placeholder Değişkenleri', + 'click_to_insert' => 'Tıklayarak editöre ekle', + 'special_placeholders' => 'Özel Placeholder\'lar', + + // Placeholder Tipleri + 'type_text' => 'Metin', + 'type_email' => 'E-posta', + 'type_url' => 'URL', + 'type_tel' => 'Telefon', + 'type_number' => 'Sayı', + 'type_textarea' => 'Çok Satırlı Metin', + 'type_richtext' => 'Zengin Metin', + 'type_markdown' => 'Markdown', + 'type_code' => 'Kod', + 'type_date' => 'Tarih', + 'type_datetime' => 'Tarih ve Saat', + 'type_time' => 'Saat', + 'type_image' => 'Resim', + 'type_images' => 'Resimler (Çoklu)', + 'type_file' => 'Dosya', + 'type_files' => 'Dosyalar (Çoklu)', + 'type_select' => 'Seçim', + 'type_multiselect' => 'Çoklu Seçim', + 'type_checkbox' => 'Onay Kutusu', + 'type_radio' => 'Radyo Butonu', + 'type_toggle' => 'Aç/Kapa', + 'type_color' => 'Renk', + 'type_tags' => 'Etiketler', +]; + diff --git a/resources/views/components/custom/example.blade.php b/resources/views/components/custom/example.blade.php new file mode 100644 index 0000000..9bfb1bc --- /dev/null +++ b/resources/views/components/custom/example.blade.php @@ -0,0 +1,6 @@ +
Bu component'i template içinde {custom.example} yazarak kullanabilirsiniz.
Bu dosyayı dilediğiniz gibi özelleştirebilir ve yeniden kullanabilirsiniz.
+Bu bir örnek custom component'tir. Bu dosyayı dilediğiniz gibi özelleştirebilirsiniz.
+Template içinde {custom.test} yazarak bu component'i çağırabilirsiniz.