Skip to content

Commit 1e0eeb4

Browse files
committed
Add custom page templates
1 parent ef2f182 commit 1e0eeb4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

config/filament-flexible-content-block-pages.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Session\Middleware\StartSession;
1414
use Illuminate\View\Middleware\ShareErrorsFromSession;
1515
use Statikbe\FilamentFlexibleContentBlockPages\FilamentFlexibleContentBlockPagesConfig;
16+
use Statikbe\FilamentFlexibleContentBlockPages\Models\Page;
1617

1718
return [
1819
'models' => [
@@ -71,4 +72,8 @@
7172
],
7273

7374
'route_helper' => \Statikbe\FilamentFlexibleContentBlockPages\Routes\LocalisedPageRouteHelper::class,
75+
76+
'page_templates' => [
77+
//Page::HOME_PAGE => 'pages.home',
78+
],
7479
];

src/FilamentFlexibleContentBlockPagesConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ public function getPanelNavigationItems(): array
160160
return $this->packageConfig('panel.navigation_items', []);
161161
}
162162

163+
public function getCustomPageTemplates(): array
164+
{
165+
return $this->packageConfig('page_templates', []);
166+
}
167+
168+
public function getCustomPageTemplate(string $code): ?string
169+
{
170+
return $this->getCustomPageTemplates()[$code] ?? null;
171+
}
172+
163173
private function packageConfig(string $configKey, $default = null): mixed
164174
{
165175
return config('filament-flexible-content-block-pages.'.$configKey, $default);

src/Http/Controllers/PageController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function index(Page $page)
4141
$this->setSEOLocalisationAndCanonicalUrl();
4242
$this->setSEOImage($page);
4343

44-
return view(self::TEMPLATE_PATH, [
44+
return view($this->getTemplatePath($page), [
4545
'page' => $page,
4646
]);
4747
}
@@ -213,4 +213,13 @@ private function getValidTitle(?string $title): ?string
213213

214214
return trim($title);
215215
}
216+
217+
private function getTemplatePath(Page $page)
218+
{
219+
if(!$page->code){
220+
return self::TEMPLATE_PATH;
221+
}
222+
223+
return FilamentFlexibleContentBlockPages::config()->getCustomPageTemplate($page->code) ?? self::TEMPLATE_PATH;
224+
}
216225
}

0 commit comments

Comments
 (0)