Add Custom Header and Footer Blade Selection: Implemented options for selecting custom Blade files for header and footer templates in the Page settings. Enhanced the PageController to render these templates dynamically, improving modularity and user experience. Updated relevant views to support this new functionality, ensuring better localization and flexibility in template management.

This commit is contained in:
Ümit Tunç
2026-01-01 10:54:38 +03:00
parent 10f2e9c9bb
commit 12441517f6
20 changed files with 587 additions and 256 deletions
@@ -10,6 +10,8 @@ use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;
use Illuminate\Support\Facades\File;
class FooterTemplateSection
{
public static function make(): Section
@@ -17,9 +19,35 @@ class FooterTemplateSection
return Section::make(__('pages.form_section_footer_template'))
->description(__('pages.form_section_footer_template_desc'))
->schema([
Select::make('custom_footer_blade')
->label('Custom Footer Blade')
->options(function () {
$files = File::glob(resource_path('views/partials/*.blade.php'));
$options = [];
foreach ($files as $file) {
$name = basename($file, '.blade.php');
$options["partials.{$name}"] = "Partial: {$name}";
}
// Add other directories if needed
$componentFiles = File::glob(resource_path('views/components/front/*.blade.php'));
foreach ($componentFiles as $file) {
$name = basename($file, '.blade.php');
$options["components.front.{$name}"] = "Component: {$name}";
}
return $options;
})
->searchable()
->preload()
->helperText('Select a physical Blade file to use as footer instead of a database template.')
->live()
->columnSpanFull(),
Select::make('footer_template_id')
->label(__('pages.footer_template_field'))
->options(FooterTemplate::where('is_active', true)->pluck('title', 'id'))
->visible(fn (Get $get) => empty($get('custom_footer_blade')))
->searchable()
->live()
->afterStateUpdated(function ($state, Set $set, Get $get) {
@@ -10,6 +10,8 @@ use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;
use Illuminate\Support\Facades\File;
class HeaderTemplateSection
{
public static function make(): Section
@@ -17,9 +19,35 @@ class HeaderTemplateSection
return Section::make(__('pages.form_section_header_template'))
->description(__('pages.form_section_header_template_desc'))
->schema([
Select::make('custom_header_blade')
->label('Custom Header Blade')
->options(function () {
$files = File::glob(resource_path('views/partials/*.blade.php'));
$options = [];
foreach ($files as $file) {
$name = basename($file, '.blade.php');
$options["partials.{$name}"] = "Partial: {$name}";
}
// Add other directories if needed
$componentFiles = File::glob(resource_path('views/components/front/*.blade.php'));
foreach ($componentFiles as $file) {
$name = basename($file, '.blade.php');
$options["components.front.{$name}"] = "Component: {$name}";
}
return $options;
})
->searchable()
->preload()
->helperText('Select a physical Blade file to use as header instead of a database template.')
->live()
->columnSpanFull(),
Select::make('header_template_id')
->label(__('pages.header_template_field'))
->options(HeaderTemplate::where('is_active', true)->pluck('title', 'id'))
->visible(fn (Get $get) => empty($get('custom_header_blade')))
->searchable()
->live()
->afterStateUpdated(function ($state, Set $set, Get $get) {
@@ -69,13 +69,14 @@ class PageSettingsSection
'landing' => __('pages.template_landing'),
'blog' => __('pages.template_blog'),
'contact' => __('pages.template_contact'),
'home' => 'Home',
])
->default('default')
->columnSpanFull(),
TextInput::make('sort_order')
->label(__('pages.sort_order_field'))
->numeric()
TextInput::make('sort_order')
->label(__('pages.sort_order_field'))
->numeric()
->default(0)
->helperText(__('pages.sort_order_helper_text'))
->columnSpanFull(),