diff --git a/config/routes.php b/config/routes.php index 95a6427684..dc49377ef6 100644 --- a/config/routes.php +++ b/config/routes.php @@ -53,4 +53,14 @@ 'middleware' => 'web', + /* + |-------------------------------------------------------------------------- + | Layout + |-------------------------------------------------------------------------- + | + | Define the default layout that will be used by front end routes. + | + */ + + 'layout' => env('STATAMIC_FRONTEND_ROUTES_LAYOUT', 'layout'), ]; diff --git a/src/Http/Controllers/FrontendController.php b/src/Http/Controllers/FrontendController.php index e315b0ef58..27cf41a096 100644 --- a/src/Http/Controllers/FrontendController.php +++ b/src/Http/Controllers/FrontendController.php @@ -45,7 +45,7 @@ public function route(Request $request, ...$args) $view = app(View::class) ->template($view) - ->layout(Arr::get($data, 'layout', 'layout')) + ->layout(Arr::get($data, 'layout', config('statamic.routes.layout', 'layout'))) ->with($data) ->cascadeContent($this->getLoadedRouteItem($data)); diff --git a/tests/Routing/RoutesTest.php b/tests/Routing/RoutesTest.php index 0da68d8226..a2b88d1e1f 100644 --- a/tests/Routing/RoutesTest.php +++ b/tests/Routing/RoutesTest.php @@ -341,4 +341,16 @@ public function it_loads_term_by_binding() $this->get('/bindings/term/title/Blog2') ->assertNotFound(); } + + #[Test] + public function it_uses_a_non_default_layout() + { + config()->set('statamic.routes.layout', 'custom-layout'); + $this->viewShouldReturnRaw('custom-layout', 'Custom layout {{ template_content }}'); + $this->viewShouldReturnRaw('test', 'Hello {{ hello }}'); + + $this->get('/basic-route-with-data') + ->assertOk() + ->assertSee('Custom layout'); + } }